Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -627,18 +627,51 @@ class C:
self.x: Final[int] = 1
```

### Explicit `Final` redeclaration

Explicit `Final` redeclaration in the same scope is accepted (shadowing).

```py
from typing import Final

x: Final = 1
x: Final = "foo"
```

### `Final` in loops

Using `Final` in a loop is not allowed.
Assignments to a module-level `Final` symbol in a loop body are treated as reassignments. `Final`
declarations in loop bodies are allowed.

```py
from typing import Final

ABC: Final[int]

for i in range(2):
ABC = i # error: [invalid-assignment] "Reassignment of `Final` symbol `ABC` is not allowed"

for _ in range(10):
# TODO: This should be an error
i: Final[int] = 1
```

### `Final` declaration in loops should enforce non-reassignment

A name declared as `Final` in a loop body should still be treated as the same binding across
iterations, so reassignments across iterations should be rejected.

```py
from typing import Final

k = ""

for i in range(10):
# TODO: This should be an error; it's a reassignment
k += " "

k: Final[str] = ""
```

### Too many arguments

```py
Expand Down