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
Prev Previous commit
Next Next commit
Add deprecation warning when calling Path with **kwargs
  • Loading branch information
uriyyo committed Dec 24, 2022
commit 6fa22de33c3563724e232bb1b1fc5ecbb46b8fcd
6 changes: 5 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,11 @@ class Path(PurePath):
"""
__slots__ = ()

def __new__(cls, *args):
def __new__(cls, *args, **kwargs):
if kwargs:
msg = ("support for supplying keyword arguments to pathlib.PurePath "
"is deprecated and scheduled for removal in Python {remove}")
warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
self = cls._from_parts(args)
Expand Down
9 changes: 5 additions & 4 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,6 @@ 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)


class PurePosixPathTest(_BasePurePathTest, unittest.TestCase):
cls = pathlib.PurePosixPath
Expand Down Expand Up @@ -2574,6 +2570,11 @@ def test_complex_symlinks_relative(self):
def test_complex_symlinks_relative_dot_dot(self):
self._check_complex_symlinks(os.path.join('dirA', '..'))

def test_passing_kwargs_deprecated(self):
with self.assertWarns(DeprecationWarning):
self.cls(foo="bar")


class WalkTests(unittest.TestCase):

def setUp(self):
Expand Down
0