Replies: 1 comment 1 reply
-
This is behavior is intended, but the reason is somewhat subtle. I'll try to explain. This is an x = 1
x = ""
def func():
reveal_type(x) # int | str Something similar is happening here with Contrast that with the case where the symbol is accessed within the same execution scope. Here, a static type checker can use code flow analysis to determine the exact narrowed type of the symbol at the point where its type is requested. x = 1
x = ""
reveal_type(x) # Literal[''] When you use The way that most package authors work around this issue is to use an aliased from __future__ import annotations
from .bar import bar as _bar
def foo() -> _bar: ... Or from __future__ import annotations
from . import bar as _bar
def foo() -> _bar.bar: ... |
Beta Was this translation helpful? Give feedback.
-
Met this one, yet couldn't find any related issues. Why this occurs and is there a workaround that would keep it just
bar
and let me still usefrom __future__ import annotations
?Beta Was this translation helpful? Give feedback.
All reactions