mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
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:
parent
1bc7a73683
commit
080cb27829
3 changed files with 10 additions and 0 deletions
|
@ -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)
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix a bug where :class:`pathlib.Path` accepted and ignored keyword arguments. Patch provided by Yurii Karabas.
|
Loading…
Add table
Add a link
Reference in a new issue