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 #196 8000 32

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
Prev Previous commit
Next Next commit
Remove kwargs from pathlib.Path; Remove redundant subclass test
  • Loading branch information
uriyyo committed Dec 17, 2022
commit f021d2b716b1f5af7859fb5e2e7035a03ed3560e
7 changes: 2 additions & 5 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class PurePath(object):
'_str', '_hash', '_pparts', '_cached_cparts',
)

def __new__(cls, *args, **kwargs):
def __new__(cls, *args):
"""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 @@ -400,9 +400,6 @@ def __new__(cls, *args, **kwargs):
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 Expand Up @@ -788,7 +785,7 @@ class Path(PurePath):
"""
__slots__ = ()

def __new__(cls, *args, **kwargs):
def __new__(cls, *args):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
self = cls._from_parts(args)
Expand Down
12 changes: 0 additions & 12 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,18 +745,6 @@ def test_kwargs(self):
with self.assertRaisesRegex(TypeError, 'got an unexpected keyword argument'):
self.cls(arg=None)

def test_subclass_kwargs(self):
# See bpo-29847
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)


class PurePosixPathTest(_BasePurePathTest, unittest.TestCase):
cls = pathlib.PurePosixPath
Expand Down
0