8000 gh-74033: Fix bug when Path takes and ignores **kwargs by uriyyo · Pull Request #19632 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-74033: Fix bug when Path takes and ignores **kwargs #19632

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

Merged
merged 13 commits into from
Jan 14, 2023
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
bpo-29847: Fix bug when Path takes and ignores **kwargs
  • Loading branch information
uriyyo committed Apr 21, 2020
commit 4228d600f3497122282bcb177b0da749dfaac807
3 changes: 3 additions & 0 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,9 @@ def __new__(cls, *args, **kwargs):
self._init()
return self

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

def _init(self,
# Private non-constructor arguments
template=None,
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 @@ -2312,6 +2312,21 @@ def test_concrete_class(self):
self.assertIs(type(p),
pathlib.WindowsPath if os.name == 'nt' else pathlib.PosixPath)

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

def test_subclass_kwargs(self):
class _PathSubclass(self.cls):
_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)

def test_unsupported_flavour(self):
if os.name == 'nt':
self.assertRaises(NotImplementedError, pathlib.PosixPath)
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 when Path takes and ignores **kwargs
0