Inheriting class with __slots__ defined
Open
Nobody has claimed this yet.
feature
priority-2-low
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
- Are you reporting a bug, or opening a feature request?
Feature request
- Please insert below the code you are checking with mypy.
class Base():
__slots__: List[str] = ['foo', 'bar']
if TYPE_CHECKING:
foo: int
bar: int
class Derived(Base):
__slots__: List[str] = ['bar']
- What is the actual behavior/output?
Success: no issues found in 1 source file
- What is the behavior/output you expect?
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.
- What are the versions of mypy and Python you are using?
Python 3.8.0, mypy 0.761
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Base and Derived slots example with mypy. Trace the type checker's handling of slots across inherited classes, then verify that a duplicate inherited slot produces a diagnostic while valid slot declarations remain accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100