from typing import Generic, TypeVar
from dataclasses import dataclass
T = TypeVar("T")
@dataclass(slots=True, weakref_slot=True)
class Token(Generic[T]):
ctx: T
print(f"{Token.__slots__=!r}")
print(f"{hasattr(Token, '__weakref__')=}")
Token.__slots__=('ctx', '__weakref__')
hasattr(Token, '__weakref__')=True
Token.__slots__=('ctx',)
hasattr(Token, '__weakref__')=False
Bug report
Bug description:
The
__weakref__slot is not set for classes that have aGeneric[T]base.Output on 3.12.2:
On 3.12.3:
CPython versions tested on:
3.12
Operating systems tested on:
Linux, macOS, Windows
Linked PRs
__weakref__not set for generic dataclasses #118099__weakref__not set for generic dataclasses (GH-118099) #118821__weakref__not set for generic dataclasses (GH-118099) #118822