electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

pyray type stubs and mypy #46

Closed frou closed 2 years ago

frou commented 2 years ago

Hi there - Firstly I'm not sure if the type stubs for pyray are supposed to be public yet (since the .pyi file was just added recently), so forgive me if I'm jumping the gun.

But from a package user perspective it seems these types aren't accessible for type-checking and won't be unless you add a py.typed file and possibly the zip_safe=False thing that are both mentioned here:

https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages

electronstudio commented 2 years ago

The pyi files were added to provide auto completion hints in PyCharm. It sounds like you want to use them for type checking? I don't know much about typed python so I'm not sure how they would be used for this.

(offtopic rant: the whole idea seems ridiculous to me - if I want a language with type safety I will use one that was actually designed for it, not one where is was bolted on afterwards. Unsafe scripting languages like python are great for quick hacks, but not for large or important projects.)

I don't know if it's a good idea to enable the pyi for type checking, because some of the types are lies. Some of those types don't exist: the pyi file just claims they do in order to provide hints that remind you what sort of C struct you're dealing with and what its C fields are named.

You could argue this lying is not a good idea, and you might be right, but it seemed pretty harmless in an auto completion. It feels like it could cause issues if you use it for actual type checking.

frou commented 2 years ago

Alright - yeah, it's probably not worth going forward with it if it's more comment-like information.

IMO there is indeed something ridiculous about typed Python, but that is the fact that it gives no benefit to runtime performance. The checking Mypy is capable of is rigorous and isn't just a wishy-washy linter type thing. If you write Python project fully annotated (they can be inline, needn't be separate stubs) then you have a significantly better static type system at your disposal than Go for example.