From 81a118292ec218fb3f4e788c743c0c070b104924 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Mon, 15 Jun 2020 23:45:18 -0600 Subject: [PATCH 1/3] bpo-19821: Deprecate pydoc.ispackage() --- Lib/pydoc.py | 2 ++ Lib/test/test_pydoc.py | 6 ++++-- .../next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 628f9fc7d1d1ef..04090163758413 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -317,6 +317,8 @@ def sort_attributes(attrs, object): def ispackage(path): """Guess whether a path refers to a package directory.""" + warnings.warn('The pydoc.ispackage() function is deprecated', + DeprecationWarning, stacklevel=2) if os.path.isdir(path): for ext in ('.py', '.pyc'): if os.path.isfile(os.path.join(path, '__init__' + ext)): diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index f0d7ffd562c9d9..9c3ddb833b2579 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -746,13 +746,15 @@ def test_splitdoc_with_description(self): def test_is_package_when_not_package(self): with test.support.temp_cwd() as test_dir: - self.assertFalse(pydoc.ispackage(test_dir)) + with self.assertWarns(DeprecationWarning): + self.assertFalse(pydoc.ispackage(test_dir)) def test_is_package_when_is_package(self): with test.support.temp_cwd() as test_dir: init_path = os.path.join(test_dir, '__init__.py') open(init_path, 'w').close() - self.assertTrue(pydoc.ispackage(test_dir)) + with self.assertWarns(DeprecationWarning): + self.assertTrue(pydoc.ispackage(test_dir)) os.remove(init_path) def test_allmethods(self): diff --git a/Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst b/Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst new file mode 100644 index 00000000000000..b45fe53ea15331 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst @@ -0,0 +1 @@ +The :func:`pydoc.ispackage()` function has been deprecated. From 7f1192454f0d65ca25f3eeff41e76435ee211b21 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 27 Dec 2023 15:43:06 +0200 Subject: [PATCH 2/3] Add a What's New entry. --- Doc/whatsnew/3.13.rst | 3 +++ .../next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index c905cddc6cba62..4b02ecddd63b27 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -556,6 +556,9 @@ Deprecated coroutine. (Contributed by Irit Katriel in :gh:`81137`.) +* Deprecate undocumented :func:`!pydoc.ispackage` function. + (Contributed by Zackery Spytz in :gh:`64020`.) + Pending Removal in Python 3.14 ------------------------------ diff --git a/Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst b/Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst index b45fe53ea15331..ede68106b56ff8 100644 --- a/Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst +++ b/Misc/NEWS.d/next/Library/2020-06-15-23-44-53.bpo-19821.ihBk39.rst @@ -1 +1 @@ -The :func:`pydoc.ispackage()` function has been deprecated. +The :func:`!pydoc.ispackage` function has been deprecated. From 368954cd6e062e4fec3f1f6f42b83cc7971b79ab Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 27 Dec 2023 15:46:11 +0200 Subject: [PATCH 3/3] Test the stacklevel. --- Lib/test/test_pydoc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 62e528161de9b4..99b19d01783a10 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -745,16 +745,18 @@ def test_splitdoc_with_description(self): def test_is_package_when_not_package(self): with os_helper.temp_cwd() as test_dir: - with self.assertWarns(DeprecationWarning): + with self.assertWarns(DeprecationWarning) as cm: self.assertFalse(pydoc.ispackage(test_dir)) + self.assertEqual(cm.filename, __file__) def test_is_package_when_is_package(self): with os_helper.temp_cwd() as test_dir: init_path = os.path.join(test_dir, '__init__.py') open(init_path, 'w').close() - with self.assertWarns(DeprecationWarning): + with self.assertWarns(DeprecationWarning) as cm: self.assertTrue(pydoc.ispackage(test_dir)) os.remove(init_path) + self.assertEqual(cm.filename, __file__) def test_allmethods(self): # issue 17476: allmethods was no longer returning unbound methods.