]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-74033: Fix bug when Path takes and ignores **kwargs (GH-19632)
authorYurii Karabas <1998uriyyo@gmail.com>
Sat, 14 Jan 2023 00:05:43 +0000 (02:05 +0200)
committerGitHub <noreply@github.com>
Sat, 14 Jan 2023 00:05:43 +0000 (16:05 -0800)
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
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Library/2020-04-18-17-45-03.bpo-29847.Uxtbq0.rst [new file with mode: 0644]

index a0678f61b63211d52985f860636016799eb755e5..ae7a62f8a4cd65ed3bbb6ef3f15297c4fc2dee93 100644 (file)
@@ -713,6 +713,10 @@ class Path(PurePath):
     __slots__ = ()
 
     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)
index 7d4d782cf5f075d37ed575937e74db37bc7c3541..1fe242b7f6ab142c74cbadde5f1f11bd6be82530 100644 (file)
@@ -2571,6 +2571,11 @@ class _BasePathTest(object):
     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):
diff --git a/Misc/NEWS.d/next/Library/2020-04-18-17-45-03.bpo-29847.Uxtbq0.rst b/Misc/NEWS.d/next/Library/2020-04-18-17-45-03.bpo-29847.Uxtbq0.rst
new file mode 100644 (file)
index 0000000..010d775
--- /dev/null
@@ -0,0 +1 @@
+Fix a bug where :class:`pathlib.Path` accepted and ignored keyword arguments. Patch provided by Yurii Karabas.