pyright
pyright copied to clipboard
"could not be determined because it refers to itself" error occurs depending on variable name and string literal value
Describe the bug
When enableExperimentalFeatures is enabled, if a string literal value matches the name of a variable in certain situation, Type of "..." could not be determined because it refers to itself is reported.
Code or Screenshots
- foo.py
# identity decorator
def w(_: str):
return lambda a: a
@w("z")
def x():
return
def y():
return x
z = y() # variable name 'z' must match the string literal passed to the decorator
reveal_type(z)
- pyrightconfig.json
{
"enableExperimentalFeatures": true
}
$ pyright --version
pyright 1.1.401
$ pyright foo.py
foo.py
foo.py:10:12 - error: Type of "x" could not be determined because it refers to itself (reportGeneralTypeIssues)
foo.py:13:13 - information: Type of "z" is "Unknown"
1 error, 0 warnings, 1 information
when the variable name is changed from z to z2, everything works fine.
$ pyright foo.py
foo.py
foo.py:13:13 - information: Type of "z2" is "() -> None"
0 errors, 0 warnings, 1 information
VS Code extension or command-line
command-line tool, 1.1.401
not reproducible in 1.1.412