Wrong type reported when type is correct
Closed this issue · 1 comments
Rizhiy commented
Describe the bug
In the following code:
from _thread import LockType
from threading import Lock
lock: LockType = Lock()
I get the following error:
error: Expression of type "Lock" is incompatible with declared type "LockType"
"Lock" is incompatible with "LockType" (reportAssignmentType)
But Lock
does return LockType
(it is actually a function), e.g. for me (python 3.11):
# python3.11/threading.py
_allocate_lock = _thread.allocate_lock
Lock = _allocate_lock
# python3.11
VS Code extension or command-line
Command line:
Python 3.11.7
pyright 1.1.364
erictraut commented
Pyright is working correctly here, so I don't consider this a bug.
Pyright, like other type checkers such as mypy, bases its type analysis on type information provided in type stub files provided by the typeshed project. You can see how the stubs define the Lock
class here.
If you think this type information is incorrect, please file a bug with the typeshed project.