mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
pathlib ABCs: drop partial, broken, untested support for bytes
paths. (#114777)
Methods like `full_match()`, `glob()`, etc, are difficult to make work with byte paths, and it's not worth the effort. This patch makes `PurePathBase` raise `TypeError` when given non-`str` path segments.
This commit is contained in:
parent
1667c28686
commit
574291963f
3 changed files with 29 additions and 21 deletions
|
@ -155,6 +155,31 @@ class DummyPurePathTest(unittest.TestCase):
|
|||
P('a/b/c')
|
||||
P('/a/b/c')
|
||||
|
||||
def test_bytes(self):
|
||||
P = self.cls
|
||||
with self.assertRaises(TypeError):
|
||||
P(b'a')
|
||||
with self.assertRaises(TypeError):
|
||||
P(b'a', 'b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a', b'b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a').joinpath(b'b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a') / b'b'
|
||||
with self.assertRaises(TypeError):
|
||||
b'a' / P('b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a').match(b'b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a').relative_to(b'b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a').with_name(b'b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a').with_stem(b'b')
|
||||
with self.assertRaises(TypeError):
|
||||
P('a').with_suffix(b'b')
|
||||
|
||||
def _check_str_subclass(self, *args):
|
||||
# Issue #21127: it should be possible to construct a PurePath object
|
||||
# from a str subclass instance, and it then gets converted to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue