Skip to content

Commit 383486c

Browse files
committed
stubtest: do not require @disjoint_base if there are __slots__
1 parent d1c6904 commit 383486c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

mypy/stubtest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ def _verify_disjoint_base(
510510
if stub.is_final:
511511
return
512512
is_disjoint_runtime = _is_disjoint_base(runtime)
513-
if is_disjoint_runtime and not stub.is_disjoint_base:
513+
# Don't complain about missing @disjoint_base if there are __slots__, because
514+
# in that case we can infer that it's a disjoint base.
515+
if is_disjoint_runtime and not stub.is_disjoint_base and stub.slots is None:
514516
yield Error(
515517
object_path,
516518
"is a disjoint base at runtime, but isn't marked with @disjoint_base in the stub",

mypy/test/teststubtest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,19 @@ class BytesEnum(bytes, enum.Enum):
14301430
""",
14311431
error=None,
14321432
)
1433+
yield Case(
1434+
stub="""
1435+
class HasSlotsAndNothingElse:
1436+
__slots__ = ("x",)
1437+
x: int
1438+
""",
1439+
runtime="""
1440+
class HasSlotsAndNothingElse:
1441+
__slots__ = ("x",)
1442+
x: int
1443+
""",
1444+
error=None,
1445+
)
14331446

14341447
@collect_cases
14351448
def test_decorator(self) -> Iterator[Case]:

0 commit comments

Comments
 (0)