10000 gh-74033: Fix bug when Path takes and ignores **kwargs (GH-19632) · python/cpython@080cb27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 080cb27

Browse 8000 files
authored
gh-74033: Fix bug when Path takes and ignores **kwargs (GH-19632)
Fix a bug where `Path` takes and ignores `**kwargs` by adding to `PurePath` class `__init__` method which can take only positional arguments. Automerge-Triggered-By: GH:brettcannon
1 parent 1bc7a73 commit 080cb27

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/pathlib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ class Path(PurePath):
713713
__slots__ = ()
714714

715715
def __new__(cls, *args, **kwargs):
716+
if kwargs:
717+
msg = ("support for supplying keyword arguments to pathlib.PurePath "
718+
"is deprecated and scheduled for removal in Python {remove}")
719+
warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
716720
if cls is Path:
717721
cls = WindowsPath if os.name == 'nt' else PosixPath
718722
self = cls._from_parts(args)

Lib/test/test_pathlib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,11 @@ def test_complex_symlinks_relative(self):
25712571
def test_complex_symlinks_relative_dot_dot(self):
25722572
self._check_complex_symlinks(os.path.join('dirA', '..'))
25732573

2574+
def test_passing_kwargs_deprecated(self):
2575+
with self.assertWarns(DeprecationWarning):
2576+
self.cls(foo="bar")
2577+
2578+
25742579
class WalkTests(unittest.TestCase):
25752580

25762581
def setUp(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug where :class:`pathlib.Path 345F ` accepted and ignored keyword arguments. Patch provided by Yurii Karabas.

0 commit comments

Comments
 (0)
0