You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal is to create stubs for myapp.
The manage.py is used to temporary host the import instruction, but any other py file would be fine. import mysite.myapp doesn't raise an error.
import myapp raises an expected error: Import "myapp" could not be resolved
So, we need to make the module visible. How?
I tried the setting of PYTHONPATH in .env, but it doesn't help (seems to have no effect for the purpose)
I tried to set Python › Analysis: Extra Paths. It works too much, in the sense that the module could be found and there is no "Stub file not found for ..." error.
My solution is to add a python path file: D:\Python37\Lib\site-packages\tmp.pth, containing D:/root/mysite.
After a "Restart Language Server", I finally have the wanted error: Stub file not found for "myapp" Pylance (reportMissingTypeStubs)
with the Quick Fix: Create Type Stub For "myapp".
The question is: is there a smoother way to generate the typings?
The text was updated successfully, but these errors were encountered:
The "create stub" feature is intended for installed packages. If you plan to make your package into an installable package, you could do an editable install into your current Python environment. Then Pylance will be able to create stubs from it.
However, if you plan to ship your library as Python source code, I recommend simply annotating your Python code and including a "py.typed" file (as described in PEP 561) in your package. That would save you the effort of creating and maintaining a separate set of type stubs.
I give the preference to stub files over inline types. Even Pyright, in type-stubs.md, says "it’s highly recommended that you use type stub files for all external imports.".
About an installable package (pip install --editable, I suppose) I'm not used to this option, but it think it does the same as my mentioned tmp.path, with the regular easy-install.pth.
I wanted to be sure to not miss something simpler, so thanks again.
I want to create stub files for my project, not for an existing library (described in https://github.com/microsoft/pyright/blob/master/docs/type-stubs.md). Part of the project is aimed to be published as a library, eventually, with these typings.
The project is designed for Django. The simplified layout looks like:
The goal is to create stubs for
myapp
.The
manage.py
is used to temporary host the import instruction, but any other py file would be fine.import mysite.myapp
doesn't raise an error.import myapp
raises an expected error:Import "myapp" could not be resolved
So, we need to make the module visible. How?
Python › Analysis: Extra Paths
. It works too much, in the sense that the module could be found and there is no "Stub file not found for ..." error.My solution is to add a python path file:
D:\Python37\Lib\site-packages\tmp.pth
, containingD:/root/mysite
.After a "Restart Language Server", I finally have the wanted error:
Stub file not found for "myapp" Pylance (reportMissingTypeStubs)
with the Quick Fix:
Create Type Stub For "myapp"
.The question is: is there a smoother way to generate the typings?
The text was updated successfully, but these errors were encountered: