python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.65k stars 2.86k forks source link

Inheriting class with __slots__ defined #8358

Open dhalenok opened 4 years ago

dhalenok commented 4 years ago

Feature request

class Base():
    __slots__: List[str] = ['foo', 'bar']
    if TYPE_CHECKING:
        foo: int
        bar: int

class Derived(Base):
    __slots__: List[str] = ['bar']

Success: no issues found in 1 source file

I believe it would be nice if mypy generated an error on __slots__ declaration in Derived class because 'bar' slot was already declared in Base class.

Python 3.8.0, mypy 0.761

JukkaL commented 4 years ago

The redundant slot definition seems to work at runtime, so this seems pretty low priority.

dhalenok commented 4 years ago

@JukkaL Agree. On a side note, having the redundant slot wastes some memory.