Open KotlinIsland opened 2 years ago
Interesting case 🤔
Forward references are allowed in https://www.python.org/dev/peps/pep-0613/#forward-references
But, I think that AMONGUS | IMPOSTER
should be an error in mypy in this case.
We have to track what value was actually used for creating a type alias: real or forward ref.
And when using new-style unions we can check that |
operator is supported for these types.
This is quite hard to fix. Because AssignmentStmt
does not have something like .annotation_expr
.
Fields that are present at the moment: https://github.com/python/mypy/blob/b47245adc60eecde9164799c426f3bffcedbc48e/mypy/nodes.py#L1104-L1121
So, my plan is:
annotation_expr
field to AssignmentStmt
, assign it during fastparse.py
semanal.py
checker.py
stageI am not going to touch anything related to .type
or .unanalyzed_type
, so it should be fine.
Moreover, we need to change how semanal
binds types somehow for this case.
Because we need to make sure that semanal
understands that AMONGUS: TypeAlias = "int"
is str
, not TypeAlias[int]
when analyzed as an annotation.
@KotlinIsland take a look at #11611
@sobolevn Looks good! but does that handle None
(None
and str
s are the only two fake types that I know of).
None | None
currently is okay with mypy.
Any types in a new union syntax that are fake(looking at you
None
) will be runtime errors.