bpo-38994: Implement __class_getitem__ for PathLike (GH-17498)
https://bugs.python.org/issue38994
This commit is contained in:
parent
cd90a52983
commit
526606baf7
|
@ -1072,6 +1072,9 @@ class PathLike(abc.ABC):
|
||||||
def __subclasshook__(cls, subclass):
|
def __subclasshook__(cls, subclass):
|
||||||
return hasattr(subclass, '__fspath__')
|
return hasattr(subclass, '__fspath__')
|
||||||
|
|
||||||
|
def __class_getitem__(cls, type):
|
||||||
|
return cls
|
||||||
|
|
||||||
|
|
||||||
if name == 'nt':
|
if name == 'nt':
|
||||||
class _AddedDllDirectory:
|
class _AddedDllDirectory:
|
||||||
|
|
|
@ -777,6 +777,9 @@ class PurePath(object):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
return self._cparts >= other._cparts
|
return self._cparts >= other._cparts
|
||||||
|
|
||||||
|
def __class_getitem__(cls, type):
|
||||||
|
return cls
|
||||||
|
|
||||||
drive = property(attrgetter('_drv'),
|
drive = property(attrgetter('_drv'),
|
||||||
doc="""The drive prefix (letter or UNC path), if any.""")
|
doc="""The drive prefix (letter or UNC path), if any.""")
|
||||||
|
|
||||||
|
|
|
@ -4048,6 +4048,9 @@ class TestPEP519(unittest.TestCase):
|
||||||
self.assertRaises(ZeroDivisionError, self.fspath,
|
self.assertRaises(ZeroDivisionError, self.fspath,
|
||||||
FakePath(ZeroDivisionError()))
|
FakePath(ZeroDivisionError()))
|
||||||
|
|
||||||
|
def test_pathlike_class_getitem(self):
|
||||||
|
self.assertIs(os.PathLike[bytes], os.PathLike)
|
||||||
|
|
||||||
|
|
||||||
class TimesTests(unittest.TestCase):
|
class TimesTests(unittest.TestCase):
|
||||||
def test_times(self):
|
def test_times(self):
|
||||||
|
|
|
@ -2217,6 +2217,9 @@ class _BasePathTest(object):
|
||||||
class PathTest(_BasePathTest, unittest.TestCase):
|
class PathTest(_BasePathTest, unittest.TestCase):
|
||||||
cls = pathlib.Path
|
cls = pathlib.Path
|
||||||
|
|
||||||
|
def test_class_getitem(self):
|
||||||
|
self.assertIs(self.cls[str], self.cls)
|
||||||
|
|
||||||
def test_concrete_class(self):
|
def test_concrete_class(self):
|
||||||
p = self.cls('a')
|
p = self.cls('a')
|
||||||
self.assertIs(type(p),
|
self.assertIs(type(p),
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Implement ``__class_getitem__`` for ``os.PathLike``, ``pathlib.Path``
|
Loading…
Reference in New Issue