basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

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

Open ilkiri23 opened this issue 1 year ago • 3 comments

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
...

ilkiri23 avatar Jun 07 '24 20:06 ilkiri23

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

DetachHead avatar Jun 08 '24 00:06 DetachHead

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

ilkiri23 avatar Jun 11 '24 06:06 ilkiri23

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

DetachHead avatar Jun 11 '24 07:06 DetachHead