]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-117337: Deprecate `glob.glob0()` and `glob.glob1()`. (#117371)
authorBarney Gale <barney.gale@gmail.com>
Mon, 1 Apr 2024 19:37:41 +0000 (20:37 +0100)
committerGitHub <noreply@github.com>
Mon, 1 Apr 2024 19:37:41 +0000 (19:37 +0000)
These undocumented functions are no longer used by `msilib`, so there's no
reason to keep them around.

Doc/whatsnew/3.13.rst
Lib/glob.py
Lib/test/test_glob.py
Misc/NEWS.d/next/Library/2024-03-29-15-58-01.gh-issue-117337.7w3Qwp.rst [new file with mode: 0644]

index 97bee4d38e300aac30c892312e39c2b1308775c1..7f6a86efc61bf751d3f87de6364e827b933502fd 100644 (file)
@@ -813,6 +813,11 @@ Deprecated
   translation was not found.
   (Contributed by Serhiy Storchaka in :gh:`88434`.)
 
+* :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
   :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
index d59641195a1c4118ac71c344e1f9cedb45ab1e8b..a915cf0bdf45023792317e2756ad6b4e1b520d46 100644 (file)
@@ -119,12 +119,19 @@ 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 and pass a directory to its root_dir argument 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
index 6719bdbb0cc9b1fda78171395706ee2864f5e865..70ee35ed2850bc0c82d14c40400f0012702e3daa 100644 (file)
@@ -4,6 +4,7 @@ import re
 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,6 +383,36 @@ class GlobTests(unittest.TestCase):
             for it in iters:
                 self.assertEqual(next(it), p)
 
+    def test_glob0(self):
+        with self.assertWarns(DeprecationWarning):
+            glob.glob0(self.tempdir, 'a')
+
+        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'))
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 (file)
index 0000000..73bd256
--- /dev/null
@@ -0,0 +1,3 @@
+Deprecate undocumented :func:`!glob.glob0` and :func:`!glob.glob1`
+functions. Use :func:`glob.glob` and pass a directory to its
+*root_dir* argument instead.