Closed walles closed 3 years ago
@walles
It seems good enhancement to me.
Actually, I have not used mypy.
So, I would like to know why adding py.typed
file is useful.
Does py.typed
reduce the process time from mypy?
Is py.typed
useful for other type checking tools (e.g. VSCode)?
You should use mypy
, Guido of I-started-Python fame is the number four top contributor :).
Anyway, adding py.typed
moves mypy
from "doesn't work at all" to "produces useful typing warnings".
Don't know about other tools, but personally I have the "Python > Linting: Mypy Enabled" box checked in VSCode. And without py.typed
its helpfulness is limited, so from my perspective putting a py.typed
file in there would definitely improve my VSCode experience.
Also, having the py.typed
file is part of PEP-561, and following that PEP at least shouldn't hurt any other tool:
Package maintainers who wish to support type checking of their code MUST add a marker file named
py.typed
to their package supporting typing.
py.typed
On my Find-Bad Motion Tracks Blender add-on.
(env) ~/s/find_bad_motion_tracks (main|✔) $ mypy __init__.py
__init__.py:14: error: Skipping analyzing "bpy": found module but no type hints or library stubs
__init__.py:14: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
__init__.py:19: error: Skipping analyzing "bpy.types": found module but no type hints or library stubs
Found 2 errors in 1 file (checked 1 source file)
py.typed
(env) ~/s/find_bad_motion_tracks (main|✔) [1] $ mypy __init__.py
Success: no issues found in 1 source file
(env) ~/s/find_bad_motion_tracks (main|✔) $
Thanks for your detail information. I will tackle this from now.
This enhancement has been merged.
As a developer, I like to use
mypy
to type check my Python code. This converts various runtime problems into much simpler compile time problems and saves me time.For
mypy
to use the stubs generated byfake-bpy-module
, the resultingbpy
package needs to come with apy.typed
marker file.The good news is that a lot of the
bpy.types
already come with type annotations (yay!), and adding this file here is the only thing left to letmypy
benefit from them.Example
Note the (empty)
py.typed
file I manually added in here.Are you willing to contribute about this feature. (Yes/No)
Possibly.