Skip to content

Commit e324460

Browse files
ilevkivskyiIvan Levkivskyi
and
Ivan Levkivskyi
authored
Clear type alias flag for assignments that are not aliases (#11446)
This flag may be set to `True` if there are tricky forward references. Co-authored-by: Ivan Levkivskyi <[email protected]>
1 parent 5703bec commit e324460

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mypy/semanal.py

+4
Original file line numberDiff line numberDiff line change
@@ -2044,9 +2044,13 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
20442044
special_form = True
20452045
elif self.analyze_enum_assign(s):
20462046
special_form = True
2047+
20472048
if special_form:
20482049
self.record_special_form_lvalue(s)
20492050
return
2051+
# Clear the alias flag if assignment turns out not a special form after all. It
2052+
# may be set to True while there were still placeholders due to forward refs.
2053+
s.is_alias_def = False
20502054

20512055
# OK, this is a regular assignment, perform the necessary analysis steps.
20522056
s.is_final_def = self.unwrap_final(s)

test-data/unit/check-callable.test

+14
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,17 @@ Some.bad_cls_method(1) # E: Too many arguments for "bad_cls_method" of "Some" \
545545
s.bad_st_method(1) # E: Too many arguments for "bad_st_method" of "Some"
546546
Some.bad_st_method(1) # E: Too many arguments for "bad_st_method" of "Some"
547547
[builtins fixtures/callable.pyi]
548+
549+
[case testClassMethodAliasStub]
550+
from a import f
551+
f("no") # E: Argument 1 has incompatible type "str"; expected "int"
552+
[file a.pyi]
553+
from b import C
554+
f = C.f
555+
[file b.pyi]
556+
import a
557+
class C(B):
558+
@classmethod
559+
def f(self, x: int) -> C: ...
560+
class B: ...
561+
[builtins fixtures/classmethod.pyi]

0 commit comments

Comments
 (0)