From 2468f332ba4df9fa50597c43da6480100ae334a0 Mon Sep 17 00:00:00 2001 From: barneygale Date: Wed, 8 May 2024 20:40:59 +0100 Subject: [PATCH 1/4] GH-74033: Drop deprecated `pathlib.Path()` keyword arguments Remove support for supplying keyword arguments to `pathlib.Path()`. This has been deprecated since Python 3.12. --- Doc/whatsnew/3.14.rst | 5 +++++ Lib/pathlib/_local.py | 9 +-------- Lib/test/test_pathlib/test_pathlib.py | 4 ---- .../2024-05-08-20-41-48.gh-issue-74033.YebHZj.rst | 1 + 4 files changed, 7 insertions(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-05-08-20-41-48.gh-issue-74033.YebHZj.rst diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 14628f666dd079..6aaa8bb2c74be4 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -101,6 +101,11 @@ Deprecated Removed ======= +pathlib +------- + +* Remove support for passing additional keyword arguments to + :class:`pathlib.Path`. In previous versions, any such arguments are ignored. Porting to Python 3.14 diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index b1e678aceb9ce8..cf0db539724d62 100644 --- a/Lib/pathlib/_local.py +++ b/Lib/pathlib/_local.py @@ -4,7 +4,6 @@ import os import posixpath import sys -import warnings from glob import _StringGlobber from itertools import chain from _collections_abc import Sequence @@ -417,6 +416,7 @@ def is_absolute(self): def is_reserved(self): """Return True if the path contains one of the special names reserved by the system, if any.""" + import warnings msg = ("pathlib.PurePath.is_reserved() is deprecated and scheduled " "for removal in Python 3.15. Use os.path.isreserved() to " "detect reserved paths on Windows.") @@ -495,13 +495,6 @@ class Path(PathBase, PurePath): def _unsupported_msg(cls, attribute): return f"{cls.__name__}.{attribute} is unsupported on this system" - def __init__(self, *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)) - super().__init__(*args) - def __new__(cls, *args, **kwargs): if cls is Path: cls = WindowsPath if os.name == 'nt' else PosixPath diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 5fd1a41cbee17b..d60a4dc5a30cc6 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1121,10 +1121,6 @@ def test_is_mount_root(self): self.assertTrue(R.is_mount()) self.assertFalse((R / '\udfff').is_mount()) - def test_passing_kwargs_deprecated(self): - with self.assertWarns(DeprecationWarning): - self.cls(foo="bar") - def setUpWalk(self): super().setUpWalk() sub21_path= self.sub2_path / "SUB21" diff --git a/Misc/NEWS.d/next/Library/2024-05-08-20-41-48.gh-issue-74033.YebHZj.rst b/Misc/NEWS.d/next/Library/2024-05-08-20-41-48.gh-issue-74033.YebHZj.rst new file mode 100644 index 00000000000000..e6ff47e1a3e57b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-08-20-41-48.gh-issue-74033.YebHZj.rst @@ -0,0 +1 @@ +Drop support for passing keyword arguments to :class:`pathlib.Path`. From 53783e47acf10714c7c49116d29c85d820aee352 Mon Sep 17 00:00:00 2001 From: barneygale Date: Fri, 10 May 2024 18:04:36 +0100 Subject: [PATCH 2/4] Fix encoding warnings test --- Lib/test/test_io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index e5cb08c2cdd04c..6c5b72e332268a 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -4511,11 +4511,11 @@ def test_check_encoding_warning(self): ''') proc = assert_python_ok('-X', 'warn_default_encoding', '-c', code) warnings = proc.err.splitlines() - self.assertEqual(len(warnings), 4) + self.assertEqual(len(warnings), 2) self.assertTrue( warnings[0].startswith(b":5: EncodingWarning: ")) self.assertTrue( - warnings[2].startswith(b":8: EncodingWarning: ")) + warnings[1].startswith(b":8: EncodingWarning: ")) def test_text_encoding(self): # PEP 597, bpo-47000. io.text_encoding() returns "locale" or "utf-8" From aa6056ab184b190dba84e721932fba22eef6147a Mon Sep 17 00:00:00 2001 From: barneygale Date: Tue, 14 May 2024 20:46:24 +0100 Subject: [PATCH 3/4] Undo deferred import --- Lib/pathlib/_local.py | 2 +- Lib/test/test_io.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index abe6bb3cfabd6b..e094006161b929 100644 --- a/Lib/pathlib/_local.py +++ b/Lib/pathlib/_local.py @@ -4,6 +4,7 @@ import os import posixpath import sys +import warnings from glob import _StringGlobber from itertools import chain from _collections_abc import Sequence @@ -404,7 +405,6 @@ def is_absolute(self): def is_reserved(self): """Return True if the path contains one of the special names reserved by the system, if any.""" - import warnings msg = ("pathlib.PurePath.is_reserved() is deprecated and scheduled " "for removal in Python 3.15. Use os.path.isreserved() to " "detect reserved paths on Windows.") diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 6c5b72e332268a..e5cb08c2cdd04c 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -4511,11 +4511,11 @@ def test_check_encoding_warning(self): ''') proc = assert_python_ok('-X', 'warn_default_encoding', '-c', code) warnings = proc.err.splitlines() - self.assertEqual(len(warnings), 2) + self.assertEqual(len(warnings), 4) self.assertTrue( warnings[0].startswith(b":5: EncodingWarning: ")) self.assertTrue( - warnings[1].startswith(b":8: EncodingWarning: ")) + warnings[2].startswith(b":8: EncodingWarning: ")) def test_text_encoding(self): # PEP 597, bpo-47000. io.text_encoding() returns "locale" or "utf-8" From 36194a27a7a3bf480d727afed57ef1256b18d6cb Mon Sep 17 00:00:00 2001 From: barneygale Date: Tue, 14 May 2024 20:50:05 +0100 Subject: [PATCH 4/4] Re-introduce test --- Lib/test/test_pathlib/test_pathlib.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 71727adf707cb8..3df354eb25a58c 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1108,6 +1108,10 @@ def test_is_mount_root(self): self.assertTrue(R.is_mount()) self.assertFalse((R / '\udfff').is_mount()) + def test_passing_kwargs_errors(self): + with self.assertRaises(TypeError): + self.cls(foo="bar") + def setUpWalk(self): super().setUpWalk() sub21_path= self.sub2_path / "SUB21"