From 6b07f91e573ac4e504696a5043996854c39b06c1 Mon Sep 17 00:00:00 2001 From: barneygale Date: Fri, 29 Mar 2024 15:57:23 +0000 Subject: [PATCH 1/3] GH-117337: Deprecated `glob.glob0()` and `glob.glob1()`. These undocumented functions are no longer used by `msilib`, so there's no reason to keep them around. --- Doc/whatsnew/3.13.rst | 4 ++++ Lib/glob.py | 8 +++++++- Lib/test/test_glob.py | 8 ++++++++ .../2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index f50364a7ddcc2a..4e96084466fb5b 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -802,6 +802,10 @@ Deprecated translation was not found. (Contributed by Serhiy Storchaka in :gh:`88434`.) +* :mod:`glob`: Deprecated undocumented :func:`!glob.glob0` and + :func:`!glob.glob1` functions; use :func:`glob.glob` instead. + (Contributed by Barney Gale in :gh:`117337`.) + * :mod:`http.server`: :class:`http.server.CGIHTTPRequestHandler` now emits a :exc:`DeprecationWarning` as it will be removed in 3.15. Process-based CGI HTTP servers have been out of favor for a very long time. This code was diff --git a/Lib/glob.py b/Lib/glob.py index d59641195a1c41..9a0c41104e85fd 100644 --- a/Lib/glob.py +++ b/Lib/glob.py @@ -119,12 +119,18 @@ def _glob0(dirname, basename, dir_fd, dironly, include_hidden=False): return [basename] return [] -# Following functions are not public but can be used by third-party code. +_deprecated_function_message = ( + "{name} is deprecated and will be removed in Python {remove}; use glob.glob instead" +) def glob0(dirname, pattern): + import warnings + warnings._deprecated("glob.glob0", _deprecated_function_message, remove=(3, 15)) return _glob0(dirname, pattern, None, False) def glob1(dirname, pattern): + import warnings + warnings._deprecated("glob.glob1", _deprecated_function_message, remove=(3, 15)) return _glob1(dirname, pattern, None, False) # This helper function recursively yields relative pathnames inside a literal diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index 6719bdbb0cc9b1..c6d952a0427603 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -382,6 +382,14 @@ def test_glob_many_open_files(self): for it in iters: self.assertEqual(next(it), p) + def test_glob0_deprecated(self): + with self.assertWarns(DeprecationWarning): + glob.glob0(self.tempdir, 'a') + + def test_glob1_deprecated(self): + with self.assertWarns(DeprecationWarning): + glob.glob1(self.tempdir, 'a') + def test_translate_matching(self): match = re.compile(glob.translate('*')).match self.assertIsNotNone(match('foo')) diff --git a/Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst b/Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst new file mode 100644 index 00000000000000..307d6aa55d1b31 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst @@ -0,0 +1,2 @@ +Deprecate undocumented :func:`!glob.glob0` and :func:`!glob.glob1` +functions. From ba9977e0a7192d70042e8d29b30c6f1205151d96 Mon Sep 17 00:00:00 2001 From: barneygale Date: Fri, 29 Mar 2024 16:10:13 +0000 Subject: [PATCH 2/3] Add a few more tests. --- Lib/test/test_glob.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index c6d952a0427603..70ee35ed2850bc 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -4,6 +4,7 @@ import shutil import sys import unittest +import warnings from test.support.os_helper import (TESTFN, skip_unless_symlink, can_symlink, create_empty_file, change_cwd) @@ -382,14 +383,36 @@ def test_glob_many_open_files(self): for it in iters: self.assertEqual(next(it), p) - def test_glob0_deprecated(self): + def test_glob0(self): with self.assertWarns(DeprecationWarning): glob.glob0(self.tempdir, 'a') - def test_glob1_deprecated(self): + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + eq = self.assertSequencesEqual_noorder + eq(glob.glob0(self.tempdir, 'a'), ['a']) + eq(glob.glob0(self.tempdir, '.bb'), ['.bb']) + eq(glob.glob0(self.tempdir, '.b*'), []) + eq(glob.glob0(self.tempdir, 'b'), []) + eq(glob.glob0(self.tempdir, '?'), []) + eq(glob.glob0(self.tempdir, '*a'), []) + eq(glob.glob0(self.tempdir, 'a*'), []) + + def test_glob1(self): with self.assertWarns(DeprecationWarning): glob.glob1(self.tempdir, 'a') + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + eq = self.assertSequencesEqual_noorder + eq(glob.glob1(self.tempdir, 'a'), ['a']) + eq(glob.glob1(self.tempdir, '.bb'), ['.bb']) + eq(glob.glob1(self.tempdir, '.b*'), ['.bb']) + eq(glob.glob1(self.tempdir, 'b'), []) + eq(glob.glob1(self.tempdir, '?'), ['a']) + eq(glob.glob1(self.tempdir, '*a'), ['a', 'aaa']) + eq(glob.glob1(self.tempdir, 'a*'), ['a', 'aaa', 'aab']) + def test_translate_matching(self): match = re.compile(glob.translate('*')).match self.assertIsNotNone(match('foo')) From 69b4606bae9d949dccbf93ca18033f077647c998 Mon Sep 17 00:00:00 2001 From: barneygale Date: Mon, 1 Apr 2024 19:11:32 +0100 Subject: [PATCH 3/3] Mention root_dir --- Doc/whatsnew/3.13.rst | 5 +++-- Lib/glob.py | 3 ++- .../Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 4e96084466fb5b..d671d7584692e3 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -802,8 +802,9 @@ Deprecated translation was not found. (Contributed by Serhiy Storchaka in :gh:`88434`.) -* :mod:`glob`: Deprecated undocumented :func:`!glob.glob0` and - :func:`!glob.glob1` functions; use :func:`glob.glob` instead. +* :mod:`glob`: The undocumented :func:`!glob.glob0` and :func:`!glob.glob1` + functions are deprecated. Use :func:`glob.glob` and pass a directory to its + *root_dir* argument instead. (Contributed by Barney Gale in :gh:`117337`.) * :mod:`http.server`: :class:`http.server.CGIHTTPRequestHandler` now emits a diff --git a/Lib/glob.py b/Lib/glob.py index 9a0c41104e85fd..a915cf0bdf4502 100644 --- a/Lib/glob.py +++ b/Lib/glob.py @@ -120,7 +120,8 @@ def _glob0(dirname, basename, dir_fd, dironly, include_hidden=False): return [] _deprecated_function_message = ( - "{name} is deprecated and will be removed in Python {remove}; use glob.glob instead" + "{name} is deprecated and will be removed in Python {remove}. Use " + "glob.glob and pass a directory to its root_dir argument instead." ) def glob0(dirname, pattern): diff --git a/Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst b/Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst index 307d6aa55d1b31..73bd2569c7c9cb 100644 --- a/Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst +++ b/Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst @@ -1,2 +1,3 @@ Deprecate undocumented :func:`!glob.glob0` and :func:`!glob.glob1` -functions. +functions. Use :func:`glob.glob` and pass a directory to its +*root_dir* argument instead.