Pyright: Pyright reports false error ('a' is unbound) for class attributes whose name are already defined in parent scope

Created on 11 Mar 2020  路  3Comments  路  Source: microsoft/pyright

Describe the bug

Pyright reports false error for codes like below.

# a.py
a = 0


class MyClass:
    a = a # <- Pyright says "'a' is unbound"


print(MyClass.a)

Pyright says 'a' is unbount, even though Python can run the code without any problem.

$ python a.py
0
$ npx pyright a.py
npx: installed 1 in 1.613s
typingsPath /Users/michitaro/Desktop/typings is not a valid directory.
Searching for source files
Found 1 source file
/Users/michitaro/Desktop/a.py
  5:9 - error: 'a' is unbound
  5:9 - error: 'a' is unbound
2 errors, 0 warnings
Completed in 1.288sec

To Reproduce

  1. Define a class whose attribute have a name that is already defined in outer scope.

Expected behavior

Pyright does not report any error for the code.

VS Code extension or command-line

Both VS Code extension and command-line. The version of the extension is 1.1.26.

addressed in next version bug

All 3 comments

Thanks for the bug report. This will be fixed in the next published version of Pyright.

This is now fixed in Pyright 1.1.27, which I just published.

Thank you very much for the ultra fast fix!

Was this page helpful?
0 / 5 - 0 ratings