Skip to content

Clear type alias flag for assignments that are not aliases #11446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2044,9 +2044,13 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
special_form = True
elif self.analyze_enum_assign(s):
special_form = True

if special_form:
self.record_special_form_lvalue(s)
return
# Clear the alias flag if assignment turns out not a special form after all. It
# may be set to True while there were still placeholders due to forward refs.
s.is_alias_def = False

# OK, this is a regular assignment, perform the necessary analysis steps.
s.is_final_def = self.unwrap_final(s)
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-callable.test
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,17 @@ Some.bad_cls_method(1) # E: Too many arguments for "bad_cls_method" of "Some" \
s.bad_st_method(1) # E: Too many arguments for "bad_st_method" of "Some"
Some.bad_st_method(1) # E: Too many arguments for "bad_st_method" of "Some"
[builtins fixtures/callable.pyi]

[case testClassMethodAliasStub]
from a import f
f("no") # E: Argument 1 has incompatible type "str"; expected "int"
[file a.pyi]
from b import C
f = C.f
[file b.pyi]
import a
class C(B):
@classmethod
def f(self, x: int) -> C: ...
class B: ...
[builtins fixtures/classmethod.pyi]