From: Yurii Karabas <1998uriyyo@gmail.com> Date: Sat, 14 Jan 2023 00:05:43 +0000 (+0200) Subject: gh-74033: Fix bug when Path takes and ignores **kwargs (GH-19632) X-Git-Tag: v3.12.0a5~187 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=080cb27829aa1a461d80504b32c362cbc14a5a75;p=thirdparty%2FPython%2Fcpython.git 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 --- diff --git a/Lib/pathlib.py b/Lib/pathlib.py index a0678f61b632..ae7a62f8a4cd 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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) diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 7d4d782cf5f0..1fe242b7f6ab 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -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 index 000000000000..010d775a0d98 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-04-18-17-45-03.bpo-29847.Uxtbq0.rst @@ -0,0 +1 @@ +Fix a bug where :class:`pathlib.Path` accepted and ignored keyword arguments. Patch provided by Yurii Karabas.