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
However, if the type aliases are split into another file, TYPE_FOO (using Optional) is sometimes invalid in mypy and triggers "Variable "TYPE_FOO" is not valid as a type [valid-type]" – while the functionally equivalent TYPE_BAR (using Union) is always valid. The error from Optional seems to appear on every-other invocation of mypy. I can't seem to recreate the error reliably with the small test case alone, but dropping it into larger projects seems to trigger it on every-other run.
Bug Report
I think this is a bug, as I get inconsistent results across multiple invocations.
Depending on how I define a Type Alias, it can or can not be used as a valid type in another file - on every other invocation of mypy.
However, if the type aliases are split into another file,
TYPE_FOO
(usingOptional
) is sometimes invalid in mypy and triggers "Variable "TYPE_FOO" is not valid as a type [valid-type]" – while the functionally equivalentTYPE_BAR
(usingUnion
) is always valid. The error fromOptional
seems to appear on every-other invocation of mypy. I can't seem to recreate the error reliably with the small test case alone, but dropping it into larger projects seems to trigger it on every-other run.To Reproduce
custom_types.py
project.py
Expected Behavior
I expected no errors for either usage.
I expected consistent behavior from mypy across runs when it thinks there is an issue.
Actual Behavior
MyPy alternates an error for the imported type that uses
Optional
on every-other run:i.e. The first run has no errors, the second has the error, the third has no errors, the fourth has the error, etc
The type using
Union
never triggers an error.Your Environment
1.10
NA
mypy.ini
(and other config files):check_untyped_defs = True
3.10
The text was updated successfully, but these errors were encountered: