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
This commit is contained in:
Yurii Karabas 2023-01-14 02:05:43 +02:00 committed by GitHub
parent 1bc7a73683
commit 080cb27829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View file

@ -713,6 +713,10 @@ class Path(PurePath):
__slots__ = () __slots__ = ()
def __new__(cls, *args, **kwargs): 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: if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath cls = WindowsPath if os.name == 'nt' else PosixPath
self = cls._from_parts(args) self = cls._from_parts(args)

View file

@ -2571,6 +2571,11 @@ class _BasePathTest(object):
def test_complex_symlinks_relative_dot_dot(self): def test_complex_symlinks_relative_dot_dot(self):
self._check_complex_symlinks(os.path.join('dirA', '..')) 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): class WalkTests(unittest.TestCase):
def setUp(self): def setUp(self):

View file

@ -0,0 +1 @@
Fix a bug where :class:`pathlib.Path` accepted and ignored keyword arguments. Patch provided by Yurii Karabas.