Describe the Bug
I think the following should type check, it works at runtime and no other type checker complains.
from dataclasses import dataclass
@dataclass(slots=True)
class Foo:
x: int
y: int
class Bar(Foo):
def __init__(self, x: int, y: int) -> None:
super().__init__(x, y)
self.z = x + y # ERROR
assert "__slots__" not in Bar.__dict__ # OK
assert Bar(1, 2).__dict__ == {"z": 3} # OK
ERROR sandbox.py:11:14-15: Object of class `Bar` has no attribute `z` (not declared in `__slots__`) [missing-attribute]
For non-dataclasses, pyrefly reports no error just like all other type checkers: [sandbox]
class Foo:
__slots__ = "x", "y"
def __init__(self, x: int, y: int) -> None:
self.x = x
self.y = y
class Bar(Foo):
def __init__(self, x: int, y: int) -> None:
super().__init__(x, y)
self.z = x + y # OK
Sandbox Link
https://pyrefly.org/sandbox/?project=v2.pZRBC4JAEIX_ypAHjcKlugldgrp0MDx7kRQLwhVXQ43-e29clSTZS54WeTOOs997xsg02X5qSEc9ZKn2vG7sXvvsJGW_rtrDVZX63Hyd-RnUh6hwUDEAOGNL3WXdd5j1ZZUnhbN0x8Iaaswz8W2LPda0oobIomMQ-IEGlxO24677FQaPcBHMGEZDyxjxDDhR5J9HPU-9WdOWv9kLQO8rXLTglnZvLf9FxaKLfkH91hGSYCytEMVgxw0zCymc0K0sc-UJMZTLIhVJJmJ5VWJSIYhdET2jexfw03YkO7QV2v7DqK0RtU2E2gwoFEboPg
(Only applicable for extension issues) IDE Information
No response
Describe the Bug
I think the following should type check, it works at runtime and no other type checker complains.
For non-dataclasses,
pyreflyreports no error just like all other type checkers: [sandbox]Sandbox Link
https://pyrefly.org/sandbox/?project=v2.pZRBC4JAEIX_ypAHjcKlugldgrp0MDx7kRQLwhVXQ43-e29clSTZS54WeTOOs997xsg02X5qSEc9ZKn2vG7sXvvsJGW_rtrDVZX63Hyd-RnUh6hwUDEAOGNL3WXdd5j1ZZUnhbN0x8Iaaswz8W2LPda0oobIomMQ-IEGlxO24677FQaPcBHMGEZDyxjxDDhR5J9HPU-9WdOWv9kLQO8rXLTglnZvLf9FxaKLfkH91hGSYCytEMVgxw0zCymc0K0sc-UJMZTLIhVJJmJ5VWJSIYhdET2jexfw03YkO7QV2v7DqK0RtU2E2gwoFEboPg
(Only applicable for extension issues) IDE Information
No response