stdlib: add __slots__ (#14611)

This commit is contained in:
Jelle Zijlstra
2025-08-21 07:24:59 -07:00
committed by GitHub
parent 28abff1eb3
commit f32d9f08bd
38 changed files with 247 additions and 12 deletions
+32
View File
@@ -170,6 +170,37 @@ class _DefaultFactory(Protocol[_T_co]):
def __call__(self) -> _T_co: ...
class Field(Generic[_T]):
if sys.version_info >= (3, 14):
__slots__ = (
"name",
"type",
"default",
"default_factory",
"repr",
"hash",
"init",
"compare",
"metadata",
"kw_only",
"doc",
"_field_type",
)
elif sys.version_info >= (3, 10):
__slots__ = (
"name",
"type",
"default",
"default_factory",
"repr",
"hash",
"init",
"compare",
"metadata",
"kw_only",
"_field_type",
)
else:
__slots__ = ("name", "type", "default", "default_factory", "repr", "hash", "init", "compare", "metadata", "_field_type")
name: str
type: Type[_T] | str | Any
default: _T | Literal[_MISSING_TYPE.MISSING]
@@ -355,6 +386,7 @@ def is_dataclass(obj: object) -> TypeIs[DataclassInstance | type[DataclassInstan
class FrozenInstanceError(AttributeError): ...
class InitVar(Generic[_T]):
__slots__ = ("type",)
type: Type[_T]
def __init__(self, type: Type[_T]) -> None: ...
@overload