From 7ffe7ba30fc051014977c6f393c51e57e71a6648 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 3 Feb 2022 12:25:10 +0300 Subject: [PATCH] bpo-46483: Remove `__class_getitem__` from `pathlib.PurePath` (GH-30848) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- Doc/whatsnew/3.11.rst | 3 +++ Lib/pathlib.py | 3 --- Lib/test/test_pathlib.py | 9 --------- .../Library/2022-01-23-11-17-48.bpo-46483.j7qwWb.rst | 2 -- .../Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst | 1 + 5 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2022-01-23-11-17-48.bpo-46483.j7qwWb.rst create mode 100644 Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 33f39e57752..acb21d3ccaf 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -545,6 +545,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 ====================== diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 920e1f425a0..7f4210e2b80 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -12,7 +12,6 @@ from errno import ENOENT, ENOTDIR, EBADF, ELOOP 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__ = [ @@ -604,8 +603,6 @@ class PurePath(object): 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 5e46b4ffeae..ec2baca18fd 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2450,15 +2450,6 @@ class _BasePathTest(object): 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-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 a84503d299a..00000000000 --- 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`. 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 00000000000..89cc818a9c5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-24-13-00-09.bpo-46483.9XnmKp.rst @@ -0,0 +1 @@ +Remove :meth:`~object.__class_getitem__` from :class:`pathlib.PurePath` as this class was not supposed to be generic.