Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-89812: Add pathlib._PurePathExt #104810

Closed
wants to merge 20 commits into from
Closed
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
Prev Previous commit
Next Next commit
Rename _LexicalPath --> _BasePurePath
  • Loading branch information
barneygale committed May 23, 2023
commit ace5824a9205f2e81b6aa7780c1fadb4ba7b8fc6
16 changes: 8 additions & 8 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __repr__(self):
return "<{}.parents>".format(type(self._path).__name__)


class _LexicalPath(object):
class _BasePurePath(object):
barneygale marked this conversation as resolved.
Show resolved Hide resolved
"""Base class for manipulating paths using only lexical operations.

This class does not provide __fspath__(), __bytes__() or as_uri().
barneygale marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -284,7 +284,7 @@ def __reduce__(self):
def __init__(self, *args):
paths = []
for arg in args:
if isinstance(arg, _LexicalPath):
if isinstance(arg, _BasePurePath):
path = arg._raw_path
else:
try:
Expand Down Expand Up @@ -392,7 +392,7 @@ def _parts_normcase(self):
return self._parts_normcase_cached

def __eq__(self, other):
if not isinstance(other, _LexicalPath):
if not isinstance(other, _BasePurePath):
return NotImplemented
return self._str_normcase == other._str_normcase and self._flavour is other._flavour

Expand All @@ -404,22 +404,22 @@ def __hash__(self):
return self._hash

def __lt__(self, other):
if not isinstance(other, _LexicalPath) or self._flavour is not other._flavour:
if not isinstance(other, _BasePurePath) or self._flavour is not other._flavour:
return NotImplemented
return self._parts_normcase < other._parts_normcase

def __le__(self, other):
if not isinstance(other, _LexicalPath) or self._flavour is not other._flavour:
if not isinstance(other, _BasePurePath) or self._flavour is not other._flavour:
return NotImplemented
return self._parts_normcase <= other._parts_normcase

def __gt__(self, other):
if not isinstance(other, _LexicalPath) or self._flavour is not other._flavour:
if not isinstance(other, _BasePurePath) or self._flavour is not other._flavour:
return NotImplemented
return self._parts_normcase > other._parts_normcase

def __ge__(self, other):
if not isinstance(other, _LexicalPath) or self._flavour is not other._flavour:
if not isinstance(other, _BasePurePath) or self._flavour is not other._flavour:
return NotImplemented
return self._parts_normcase >= other._parts_normcase

Expand Down Expand Up @@ -666,7 +666,7 @@ def match(self, path_pattern, *, case_sensitive=None):
return True


class PurePath(_LexicalPath):
class PurePath(_BasePurePath):
"""Base class for manipulating paths without I/O.

PurePath represents a filesystem path and offers operations which
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def with_segments(self, *pathsegments):
return type(self)(*pathsegments, session_id=self.session_id)


class _BaseLexicalPathTest(object):
class _BaseBasePurePathTest(object):
barneygale marked this conversation as resolved.
Show resolved Hide resolved

# Keys are canonical paths, values are list of tuples of arguments
# supposed to produce equal paths.
Expand Down Expand Up @@ -684,11 +684,11 @@ def test_pickling_common(self):
self.assertEqual(str(pp), str(p))


class LexicalPathTest(_BaseLexicalPathTest, unittest.TestCase):
cls = pathlib._LexicalPath
class BasePurePathTest(_BaseBasePurePathTest, unittest.TestCase):
cls = pathlib._BasePurePath


class _BasePurePathTest(_BaseLexicalPathTest):
class _BasePurePathTest(_BaseBasePurePathTest):
def test_fspath_common(self):
P = self.cls
p = P('a/b')
Expand Down