Closed UrieW closed 4 months ago
I wasn't aware of any implementation of Python that has static type checking built in. Can you please provide detailed complete step by step instructions on how to reproduce this error? Include the full output of the error message.
Type hints are provided for the pyray module to assist IDE autocompletion, but if you try to run them through a static type checker like mypy you will encounter other problems. (For example, there is no such thing as the Color class. There's a type hint for it so you know when you're expected to supply a color tuple, but the class itself doesn't exist because it's not a Python class, it's a C struct.)
I think we could add fake type hints to the colours to make them look like Color classes for the purpose of reducing the warnings produced by static type checkers. However I'm not convinced that changing the actual type is a good idea, unless there is evidence of the tuple type causing errors.
The colours in Raylib are C 'define' macros so there is no actual equivalent possible in Python. (Python CFFI only supports int 'defines' I think.) So the choice is either tuples, which is what we've had for years with no problems, or else change them to pointers to ctype structs. The structs might improve performance, but they might reduce performance, and the change could break people's programs.
Also, I use the Color class from it just fine. It just won't take tuples. The default colors are read as tuples and not read as Colors.
Install Vscode, all python extensions and python
Install raylib by pip(it's exactly called raylib in the command line
Create a Hello World project using raylib
Turn VSCode's types checking to "strict" in settings.json
Run it after completing the project
Look at the line giving the error
I followed your directions. VSCode underlines the type inconsistencies, but the program still runs fine, so I'm unable to reproduce. You'll have to make a video or something.
Regardless, even if there is a way to make VSCode fail to run on type inconsistencies, the solution is going to be "dont enable that". The solution I proposed above will probably stop it complaining about the Color type, but there's hundreds of others in the raylib package it won't like. To repeat again, the type hints are not provided for the purpose of running them through a type checker.
Also, I use the Color class from it just fine. It just won't take tuples. The default colors are read as tuples and not read as Colors.
To repeat yet again. There is no Color class. It's a fake type hint. When you call pyray.Color() it's a generator function made to mimic the look of a class constructor.
Btw if you don’t want want the (fake) type hints at all you can delete the file pyray.pyi. The library will work fine without them and you won’t get warnings. (Unless you have your type checker set to require everything to be typed, I guess)
Typehints for the colours https://github.com/electronstudio/raylib-python-cffi/pull/131
I was trying a Hello World example, until when it came to
clear_background(),
it won't run because the default colors are recognized as tuples with literal values instead of color classes.I had strict type checking on while doing this. Please fix!!!!