[pep-0591] clarify that type checkers may not allow `Final` in loops (#1033)

This commit is contained in:
Dominik Gabi 2019-05-08 14:36:02 -07:00 committed by Guido van Rossum
parent 7fc318e844
commit 3e293e68e9
1 changed files with 3 additions and 2 deletions

View File

@ -175,8 +175,9 @@ names in type-checked code::
RATE = 300 # Error: can't assign to final attribute
Base.DEFAULT_ID = 1 # Error: can't override a final attribute
for x in [1, 2, 3]:
FOO: Final = x # Error: Cannot use Final inside a loop
Note that a type checker need not allow ``Final`` declarations inside loops
since the runtime will see multiple assignments to the same variable in
subsequent iterations.
Additionally, a type checker should prevent final attributes from
being overridden in a subclass::