From f3362f4df51bf4e744e521a24b4cf6eaf24c05cf Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Thu, 6 Jan 2022 21:02:01 +0100 Subject: [PATCH 1/5] add missing __slots__ to typing._TypeVarLike --- Lib/typing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/typing.py b/Lib/typing.py index ae1dd5c2d76891..a84269df5cd9a6 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -729,6 +729,9 @@ def __repr__(self): class _TypeVarLike: """Mixin for TypeVar-like types (TypeVar and ParamSpec).""" + + __slots__ = ('__name__', '__bound__', '__covariant__', '__contravariant__') + def __init__(self, bound, covariant, contravariant): """Used to setup TypeVars and ParamSpec's bound, covariant and contravariant attributes. @@ -805,8 +808,7 @@ def longest(x: A, y: A) -> A: Note that only type variables defined in global scope can be pickled. """ - __slots__ = ('__name__', '__bound__', '__constraints__', - '__covariant__', '__contravariant__', '__dict__') + __slots__ = ('__constraints__', '__dict__') def __init__(self, name, *constraints, bound=None, covariant=False, contravariant=False): @@ -907,8 +909,7 @@ def add_two(x: float, y: float) -> float: be pickled. """ - __slots__ = ('__name__', '__bound__', '__covariant__', '__contravariant__', - '__dict__') + __slots__ = ('__dict__', ) @property def args(self): From 4cd5d2ec3221029a03bc4ce141d29b754a3ffe5e Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Thu, 6 Jan 2022 21:33:44 +0100 Subject: [PATCH 2/5] add news entry --- .../next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst diff --git a/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst b/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst new file mode 100644 index 00000000000000..f97f8fe0419a70 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst @@ -0,0 +1,2 @@ +Add missing ``__slots__`` to ``typing._TypeVarLike``. Patch by Arie +Bovenberg. From 2c9f75ee471552a542299e5d7b8062e501154d13 Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Mon, 10 Jan 2022 17:23:27 +0100 Subject: [PATCH 3/5] remove slots from _TypeVarLike base classes --- Lib/typing.py | 6 ------ .../next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Lib/typing.py b/Lib/typing.py index a84269df5cd9a6..37a4ef04f51c0d 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -730,8 +730,6 @@ def __repr__(self): class _TypeVarLike: """Mixin for TypeVar-like types (TypeVar and ParamSpec).""" - __slots__ = ('__name__', '__bound__', '__covariant__', '__contravariant__') - def __init__(self, bound, covariant, contravariant): """Used to setup TypeVars and ParamSpec's bound, covariant and contravariant attributes. @@ -808,8 +806,6 @@ def longest(x: A, y: A) -> A: Note that only type variables defined in global scope can be pickled. """ - __slots__ = ('__constraints__', '__dict__') - def __init__(self, name, *constraints, bound=None, covariant=False, contravariant=False): self.__name__ = name @@ -909,8 +905,6 @@ def add_two(x: float, y: float) -> float: be pickled. """ - __slots__ = ('__dict__', ) - @property def args(self): return ParamSpecArgs(self) diff --git a/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst b/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst index f97f8fe0419a70..6a2a3e15f0bb11 100644 --- a/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst +++ b/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst @@ -1,2 +1,2 @@ -Add missing ``__slots__`` to ``typing._TypeVarLike``. Patch by Arie -Bovenberg. +Removed ``__slots__`` from :class:``typing.ParamSpec`` and :class:``typing.TypeVar``. +They served no purpose. Patch by Arie Bovenberg. From e6f9966d9c4439bc2d29d2ac864c3619f660cc8f Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Mon, 10 Jan 2022 17:24:33 +0100 Subject: [PATCH 4/5] cleanup diff --- Lib/typing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/typing.py b/Lib/typing.py index 37a4ef04f51c0d..d520f6b2e1b3d4 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -729,7 +729,6 @@ def __repr__(self): class _TypeVarLike: """Mixin for TypeVar-like types (TypeVar and ParamSpec).""" - def __init__(self, bound, covariant, contravariant): """Used to setup TypeVars and ParamSpec's bound, covariant and contravariant attributes. From 34ec10c27b3ae8cd5cce26e06b311487fdb26b0f Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Mon, 10 Jan 2022 18:29:58 +0100 Subject: [PATCH 5/5] fix broken link in blurb --- .../next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst b/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst index 6a2a3e15f0bb11..5ca536a97c9cd2 100644 --- a/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst +++ b/Misc/NEWS.d/next/Library/2022-01-06-21-31-14.bpo-46244.hjyfJj.rst @@ -1,2 +1,2 @@ -Removed ``__slots__`` from :class:``typing.ParamSpec`` and :class:``typing.TypeVar``. +Removed ``__slots__`` from :class:`typing.ParamSpec` and :class:`typing.TypeVar`. They served no purpose. Patch by Arie Bovenberg.