Skip to content

Commit

Permalink
Undo pickling changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 18, 2023
1 parent 305381b commit dfe7aae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
7 changes: 1 addition & 6 deletions Lib/pathlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ def __init__(self, *args):
def __reduce__(self):
# Using the parts tuple helps share interned path parts
# when pickling related paths.
args = tuple(self._tail)
if self.drive or self.root:
args = (self.drive + self.root,) + args
if self.has_trailing_sep:
args = args + ('.',)
return (self.__class__, args)
return (self.__class__, self.parts)

def __fspath__(self):
return str(self)
Expand Down
18 changes: 8 additions & 10 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ def test_div_nested(self):

def test_pickling_common(self):
P = self.cls
for pathstr in ('a', 'a/', 'a/b', 'a/b/c', '/', '/a/b', '/a/b/c', 'a/b/c/'):
with self.subTest(pathstr=pathstr):
p = P(pathstr)
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
dumped = pickle.dumps(p, proto)
pp = pickle.loads(dumped)
self.assertIs(pp.__class__, p.__class__)
self.assertEqual(pp, p)
self.assertEqual(hash(pp), hash(p))
self.assertEqual(str(pp), str(p))
p = P('/a/b')
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
dumped = pickle.dumps(p, proto)
pp = pickle.loads(dumped)
self.assertIs(pp.__class__, p.__class__)
self.assertEqual(pp, p)
self.assertEqual(hash(pp), hash(p))
self.assertEqual(str(pp), str(p))

def test_fspath_common(self):
P = self.cls
Expand Down

0 comments on commit dfe7aae

Please sign in to comment.