Closed
Description
Environment data
Pylance language server
- Language Server version: 2020.7.3
- OS and version: Windows 10 (Version 2004)
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.3
Pylance's Type Checking Mode is set to basic
Expected behaviour
Provided code should work just fine, with no errors reported.
# abstract_property.py
import abc
class NamedObject(abc.ABC):
@property
@abc.abstractmethod
def name(self) -> str:
pass
class Python(NamedObject):
name = "name"
Python()
I use @property
in combination with @abstractmethod
to show that child classes should have a typed property defined. I usually use it to indicate the necessary class variables, such as "name", "id", "version" etc. It is valid Python, and mypy
has no issues with this code:
> mypy .\abstract_property.py
Success: no issues found in 1 source file
And it is valid type check, because if I change name = "name"
to name = 42
, mypy
will complain:
> mypy .\abstract_property.py
abstract_property.py:12: error: Incompatible types in assignment (expression has type "int", base class "NamedObject" defined the type as "str")
Found 1 error in 1 file (checked 1 source file)
I expect Pylance
to at least recognize this snippet as a valid Python code, and at best report an issue if there are type mismatch (as mypy
does).
Actual behaviour
Pylance
identifies the Python
class as an abstract one and reports an error: