microsoft / microsoft/pyright

Classes with `__slots__` require that their subclasses have the same amount of slots

Open
#11,058 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**
Subclasses `__slots__` incorrectly require that the tuple be the same length as base classes.

**Code or Screenshots**
```py
# pyright: strict
import asyncio

class SpamProtocol(asyncio.Protocol):
__slots__ = ("ham", "eggs") # Tuple size mismatch, expected 0 but received 2

```

**VS Code extension or command-line**
Command Line Tool 1.1.406 (1.1.405 doesn't appear to have this issue)

Contributor guide

Open the contributing guide

Research direction

No source file or test is named in the report. Reproduce the strict-mode example with a subclass of asyncio.Protocol using two __slots__, then trace the diagnostic that reports a tuple-size mismatch; done means valid subclass slots no longer trigger that error and the regression is covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.