Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
5 changes: 4 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ class PurePath(object):
'_str', '_hash', '_pparts', '_cached_cparts',
)

def __new__(cls, *args):
def __new__(cls, *args, **kwargs):
Comment thread
uriyyo marked this conversation as resolved.
Outdated
"""Construct a PurePath from one or several strings and or existing
PurePath objects. The strings and path objects are combined so as
to yield a canonicalized path, which is incorporated into the
Expand All @@ -660,6 +660,9 @@ def __new__(cls, *args):
cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
return cls._from_parts(args)

def __init__(self, *_):
pass # bpo-29847

def __reduce__(self):
# Using the parts tuple helps share interned path parts
# when pickling related paths.
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,21 @@ def test_pickling_common(self):
self.assertEqual(hash(pp), hash(p))
self.assertEqual(str(pp), str(p))

def test_kwargs(self):
with self.assertRaisesRegex(TypeError, 'got an unexpected keyword argument'):
self.cls(arg=None)

def test_subclass_kwargs(self):
Comment thread
uriyyo marked this conversation as resolved.
Outdated
class _PathSubclass(self.cls):
Comment thread
uriyyo marked this conversation as resolved.
Outdated
_flavour = self.cls()._flavour

def __init__(self, *args, **kwargs):
self.kwargs = kwargs

_kwargs = {"a": 1, "b": 2}
p = _PathSubclass(**_kwargs)
self.assertEqual(p.kwargs, _kwargs)


class PurePosixPathTest(_BasePurePathTest, unittest.TestCase):
cls = pathlib.PurePosixPath
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ Jan Kanis
Rafe Kaplan
Jacob Kaplan-Moss
Allison Kaptur
Yurii Karabas
Janne Karila
Per Øyvind Karlsen
Anton Kasyanov
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where :class:`pathlib.Path` and its subclasses take and ignore `**kwargs`. Patch provided by Yurii Karabas.
Comment thread
uriyyo marked this conversation as resolved.
Outdated