Skip to content

New analyzer: don't reprocess member expressions that are already bound #7230

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
Jul 17, 2019
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
3 changes: 3 additions & 0 deletions mypy/newsemanal/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2673,6 +2673,9 @@ def analyze_member_lvalue(self, lval: MemberExpr, explicit_type: bool, is_final:
explicit_type: Assignment has type annotation
is_final: Is the target final
"""
if lval.node:
# This has been bound already in a previous iteration.
return
lval.accept(self)
if self.is_self_member_ref(lval):
assert self.type, "Self member outside a class"
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-final.test
Original file line number Diff line number Diff line change
Expand Up @@ -1064,3 +1064,11 @@ class B:
def __init__(self) -> None:
self.x = self.y = 1
[out]

[case testFinalInDeferredMethod]
from typing_extensions import Final

class A:
def __init__(self) -> None:
self.x = 10 # type: Final
undefined # type: ignore