Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Change the default value of PurePathBase.parser from ParserBase() to
`posixpath`. As a result, user subclasses of `PurePathBase` and `PathBase`
use POSIX path syntax by default, which is very often desirable.
  • Loading branch information
barneygale committed Nov 30, 2024
commit f5e946bfe827dd5f7b5f69c7563d3b32d4c39672
2 changes: 1 addition & 1 deletion Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PurePathBase:
# work from occurring when `resolve()` calls `stat()` or `readlink()`.
'_resolving',
)
parser = ParserBase()
parser = posixpath
_globber = PathGlobber

def __init__(self, *args):
Expand Down
40 changes: 3 additions & 37 deletions Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,6 @@ def test_unsupported_operation(self):
class PurePathBaseTest(unittest.TestCase):
cls = PurePathBase

def test_unsupported_operation_pure(self):
p = self.cls('foo')
e = UnsupportedOperation
with self.assertRaises(e):
p.drive
with self.assertRaises(e):
p.root
with self.assertRaises(e):
p.anchor
with self.assertRaises(e):
p.parts
with self.assertRaises(e):
p.parent
with self.assertRaises(e):
p.parents
with self.assertRaises(e):
p.name
with self.assertRaises(e):
p.stem
with self.assertRaises(e):
p.suffix
with self.assertRaises(e):
p.suffixes
self.assertRaises(e, p.with_name, 'bar')
self.assertRaises(e, p.with_stem, 'bar')
self.assertRaises(e, p.with_suffix, '.txt')
self.assertRaises(e, p.relative_to, '')
self.assertRaises(e, p.is_relative_to, '')
self.assertRaises(e, p.is_absolute)
self.assertRaises(e, p.match, '*')

def test_magic_methods(self):
P = self.cls
self.assertFalse(hasattr(P, '__fspath__'))
Expand All @@ -108,12 +77,11 @@ def test_magic_methods(self):
self.assertIs(P.__ge__, object.__ge__)

def test_parser(self):
self.assertIsInstance(self.cls.parser, ParserBase)
self.assertIs(self.cls.parser, posixpath)


class DummyPurePath(PurePathBase):
__slots__ = ()
parser = posixpath

def __eq__(self, other):
if not isinstance(other, DummyPurePath):
Expand Down Expand Up @@ -1367,10 +1335,9 @@ def test_unsupported_operation(self):
self.assertRaises(e, p.write_bytes, b'foo')
self.assertRaises(e, p.write_text, 'foo')
self.assertRaises(e, p.iterdir)
self.assertRaises(e, p.glob, '*')
self.assertRaises(e, p.rglob, '*')
self.assertRaises(e, lambda: list(p.glob('*')))
self.assertRaises(e, lambda: list(p.rglob('*')))
self.assertRaises(e, lambda: list(p.walk()))
self.assertRaises(e, p.absolute)
self.assertRaises(e, p.expanduser)
self.assertRaises(e, p.readlink)
self.assertRaises(e, p.symlink_to, 'foo')
Expand Down Expand Up @@ -1442,7 +1409,6 @@ class DummyPath(PathBase):
memory.
"""
__slots__ = ()
parser = posixpath

_files = {}
_directories = {}
Expand Down