DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
http://docs.basedpyright.com/
Other
613 stars 13 forks source link

relative importing from a `.py` inside a `.pyi` file doesn't work #400

Open ilkiri23 opened 1 month ago

ilkiri23 commented 1 month ago

I created stub file for flask_smorest to fix problem with typing, but after that basedpyright start to show errors about "Blueprint" is unkown import and Type of "Blueprint" is unknown

from flask.views import MethodView
from flask_smorest import Blueprint # <-

blp = Blueprint('folder')

although in typings/flask_smorest/__init__.pyi there is an import/re-export of Blueprint

"""
This type stub file was generated by pyright.
"""

from webargs.flaskparser import abort
from .spec import APISpecMixin
from .blueprint import Blueprint # <-
from .pagination import Page
...
DetachHead commented 4 weeks ago

this seems to work:

- from .blueprint import Blueprint # <-
+ from flask_smorest.blueprint import Blueprint # <-

i don't think relative imports in .pyi files are able to see the source modules. as far as i can tell this is an upstream issue

ilkiri23 commented 3 weeks ago

Thank you for quick reply! I tried to play with different imports and found a solution using an alias (as operator) in stub file

from .blueprint import Blueprint as Blueprint
DetachHead commented 3 weeks ago

that's the correct way to do a re-export anyway (see here). though i'm confused as to why that would prevent the import from being resolved at all. will investigate this