From 4ee051df022994b83244b62ca4629676be5f2229 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 24 Jan 2022 13:00:47 +0300 Subject: [PATCH 1/7] bpo-46483: remove `__class_getitem__` from `pathlib.PurePath` --- Lib/pathlib.py | 3 --- Lib/test/test_pathlib.py | 9 --------- .../Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst | 1 + 3 files changed, 1 insertion(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst diff --git a/Lib/pathlib.py b/Lib/pathlib.py index d42ee4dc90b431..e668c7722cbe59 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -12,7 +12,6 @@ from operator import attrgetter from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO from urllib.parse import quote_from_bytes as urlquote_from_bytes -from types import GenericAlias __all__ = [ @@ -691,8 +690,6 @@ def __ge__(self, other): return NotImplemented return self._cparts >= other._cparts - __class_getitem__ = classmethod(GenericAlias) - drive = property(attrgetter('_drv'), doc="""The drive prefix (letter or UNC path), if any.""") diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 1bf21120a36ca1..4e37128627e0ce 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2429,15 +2429,6 @@ def test_complex_symlinks_relative(self): def test_complex_symlinks_relative_dot_dot(self): self._check_complex_symlinks(os.path.join('dirA', '..')) - def test_class_getitem(self): - from types import GenericAlias - - alias = self.cls[str] - self.assertIsInstance(alias, GenericAlias) - self.assertIs(alias.__origin__, self.cls) - self.assertEqual(alias.__args__, (str,)) - self.assertEqual(alias.__parameters__, ()) - class PathTest(_BasePathTest, unittest.TestCase): cls = pathlib.Path diff --git a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst new file mode 100644 index 00000000000000..abc1c153350811 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst @@ -0,0 +1 @@ +Remove ``__class_getitem__`` from :class:`pathlib.PurePath` From 472fb3d1bb05409e161134f2f1ccb730fabe37d0 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 24 Jan 2022 13:18:35 +0300 Subject: [PATCH 2/7] Update 2022-01-24-13-00-09.bpo-46483.9XnmKp.rst --- .../next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst index abc1c153350811..3a8dc40d1d04c0 100644 --- a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst +++ b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst @@ -1 +1,4 @@ -Remove ``__class_getitem__`` from :class:`pathlib.PurePath` +Remove ``__class_getitem__`` from :class:`pathlib.PurePath`. + +Why? Because this class was not really generic: +`PurePath` only works with `str`. From 083550a658b3348f64d50e1c2ca34a996ac1f3b5 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 24 Jan 2022 13:19:12 +0300 Subject: [PATCH 3/7] Update 2022-01-24-13-00-09.bpo-46483.9XnmKp.rst --- .../next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst index 3a8dc40d1d04c0..cdaa04fd76d01b 100644 --- a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst +++ b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst @@ -1,4 +1,4 @@ Remove ``__class_getitem__`` from :class:`pathlib.PurePath`. Why? Because this class was not really generic: -`PurePath` only works with `str`. +``PurePath`` only works with ``str``. From 651ae47bd80eb30073ba11569eba267303f431d5 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 24 Jan 2022 13:20:46 +0300 Subject: [PATCH 4/7] Delete 2022-01-23-11-17-48.bpo-46483.j7qwWb.rst --- .../next/Library/2022-01-23-11-17-48.bpo-46483.j7qwWb.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2022-01-23-11-17-48.bpo-46483.j7qwWb.rst diff --git a/Misc/NEWS.d/next/Library/2022-01-23-11-17-48.bpo-46483.j7qwWb.rst b/Misc/NEWS.d/next/Library/2022-01-23-11-17-48.bpo-46483.j7qwWb.rst deleted file mode 100644 index a84503d299a105..00000000000000 --- a/Misc/NEWS.d/next/Library/2022-01-23-11-17-48.bpo-46483.j7qwWb.rst +++ /dev/null @@ -1,2 +0,0 @@ -Change :meth:`pathlib.PurePath.__class_getitem__` to return -:class:`types.GenericAlias`. From 2f4e1e1650150da5151eb395ada241987042cd1e Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 24 Jan 2022 14:03:33 +0300 Subject: [PATCH 5/7] Update 2022-01-24-13-00-09.bpo-46483.9XnmKp.rst --- .../next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst index cdaa04fd76d01b..f58dfb9e1a3831 100644 --- a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst +++ b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst @@ -1,4 +1,4 @@ Remove ``__class_getitem__`` from :class:`pathlib.PurePath`. -Why? Because this class was not really generic: -``PurePath`` only works with ``str``. +Why? Because this class was not really generic: +``PurePath`` only works with ``str``. From 4c61ac707c331460a31b0514c1fad0d8699749e4 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 24 Jan 2022 14:54:07 +0300 Subject: [PATCH 6/7] Update Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- .../next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst index f58dfb9e1a3831..89cc818a9c59d7 100644 --- a/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst +++ b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst @@ -1,4 +1 @@ -Remove ``__class_getitem__`` from :class:`pathlib.PurePath`. - -Why? Because this class was not really generic: -``PurePath`` only works with ``str``. +Remove :meth:`~object.__class_getitem__` from :class:`pathlib.PurePath` as this class was not supposed to be generic. From 892186109babf122fec657d64fc191832c84c16e Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 25 Jan 2022 22:45:10 +0300 Subject: [PATCH 7/7] Add entry to "What's new" --- Doc/whatsnew/3.11.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index ad421b16fbac3a..e4f6b6eafd7a34 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -562,6 +562,9 @@ Removed Python 3.4 but has been broken since Python 3.7. (Contributed by Inada Naoki in :issue:`23882`.) +* Remove ``__class_getitem__`` method from :class:`pathlib.PurePath`, + because it was not used and added by mistake in previous versions. + (Contributed by Nikita Sobolev in :issue:`46483`.) Porting to Python 3.11 ======================