From 080cb27829aa1a461d80504b32c362cbc14a5a75 Mon Sep 17 00:00:00 2001 From: Yurii Karabas <1998uriyyo@gmail.com> Date: Sat, 14 Jan 2023 02:05:43 +0200 Subject: 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 --- Lib/pathlib.py | 4 ++++ Lib/test/test_pathlib.py | 5 +++++ Misc/NEWS.d/next/Library/2020-04-18-17-45-03.bpo-29847.Uxtbq0.rst | 1 + 3 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-04-18-17-45-03.bpo-29847.Uxtbq0.rst diff --git a/Lib/pathlib.py b/Lib/pathlib.py index a0678f6..ae7a62f 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 7d4d782..1fe242b 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 0000000..010d775 --- /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. -- cgit v0.12