Closed
Description
openedon May 28, 2021
Describe the bug
Conditional initialization of a Final class variable is reported as a reassignment error on elif/else branches.
To Reproduce
from typing import Final
class A:
x: Final[int]
def __init__(self, a, b):
if a:
self.x = 1
elif b:
self.x = 2
else:
self.x = 3
No configuration file found.
No pyproject.toml file found.
stubPath /home/omer/tmp/pyright/typings is not a valid directory.
Assuming Python platform Linux
Searching for source files
Found 1 source file
/home/omer/tmp/pyright/deneme.py
/home/omer/tmp/pyright/deneme.py:10:18 - error: "x" is declared as Final and cannot be reassigned
/home/omer/tmp/pyright/deneme.py:12:18 - error: "x" is declared as Final and cannot be reassigned
2 errors, 0 warnings, 0 infos
Completed in 0.596sec
Expected behavior
No errors on the first correct assignment of a final variable regardless of branching.
VS Code extension or command-line
CLI pyright 1.1.144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment