diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/os.py | 3 | ||||
-rw-r--r-- | Lib/pathlib.py | 3 | ||||
-rw-r--r-- | Lib/test/test_os.py | 3 | ||||
-rw-r--r-- | Lib/test/test_pathlib.py | 3 |
4 files changed, 12 insertions, 0 deletions
@@ -1072,6 +1072,9 @@ class PathLike(abc.ABC): def __subclasshook__(cls, subclass): return hasattr(subclass, '__fspath__') + def __class_getitem__(cls, type): + return cls + if name == 'nt': class _AddedDllDirectory: diff --git a/Lib/pathlib.py b/Lib/pathlib.py index d70fde0..f0537cf 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -777,6 +777,9 @@ class PurePath(object): return NotImplemented return self._cparts >= other._cparts + def __class_getitem__(cls, type): + return cls + drive = property(attrgetter('_drv'), doc="""The drive prefix (letter or UNC path), if any.""") diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index bf40cb1..f44ddba 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -4048,6 +4048,9 @@ class TestPEP519(unittest.TestCase): self.assertRaises(ZeroDivisionError, self.fspath, FakePath(ZeroDivisionError())) + def test_pathlike_class_getitem(self): + self.assertIs(os.PathLike[bytes], os.PathLike) + class TimesTests(unittest.TestCase): def test_times(self): diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 058a201..b8e7fcc 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2217,6 +2217,9 @@ class _BasePathTest(object): class PathTest(_BasePathTest, unittest.TestCase): cls = pathlib.Path + def test_class_getitem(self): + self.assertIs(self.cls[str], self.cls) + def test_concrete_class(self): p = self.cls('a') self.assertIs(type(p), |