Skip to content

Commit fc8007e

Browse files
authored
GH-117337: Deprecate glob.glob0() and glob.glob1(). (#117371)
These undocumented functions are no longer used by `msilib`, so there's no reason to keep them around.
1 parent c741ad3 commit fc8007e

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,11 @@ Deprecated
813813
translation was not found.
814814
(Contributed by Serhiy Storchaka in :gh:`88434`.)
815815

816+
* :mod:`glob`: The undocumented :func:`!glob.glob0` and :func:`!glob.glob1`
817+
functions are deprecated. Use :func:`glob.glob` and pass a directory to its
818+
*root_dir* argument instead.
819+
(Contributed by Barney Gale in :gh:`117337`.)
820+
816821
* :mod:`http.server`: :class:`http.server.CGIHTTPRequestHandler` now emits a
817822
:exc:`DeprecationWarning` as it will be removed in 3.15. Process-based CGI
818823
HTTP servers have been out of favor for a very long time. This code was

Lib/glob.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,19 @@ def _glob0(dirname, basename, dir_fd, dironly, include_hidden=False):
119119
return [basename]
120120
return []
121121

122-
# Following functions are not public but can be used by third-party code.
122+
_deprecated_function_message = (
123+
"{name} is deprecated and will be removed in Python {remove}. Use "
124+
"glob.glob and pass a directory to its root_dir argument instead."
125+
)
123126

124127
def glob0(dirname, pattern):
128+
import warnings
129+
warnings._deprecated("glob.glob0", _deprecated_function_message, remove=(3, 15))
125130
return _glob0(dirname, pattern, None, False)
126131

127132
def glob1(dirname, pattern):
133+
import warnings
134+
warnings._deprecated("glob.glob1", _deprecated_function_message, remove=(3, 15))
128135
return _glob1(dirname, pattern, None, False)
129136

130137
# This helper function recursively yields relative pathnames inside a literal

Lib/test/test_glob.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
import sys
66
import unittest
7+
import warnings
78

89
from test.support.os_helper import (TESTFN, skip_unless_symlink,
910
can_symlink, create_empty_file, change_cwd)
@@ -382,6 +383,36 @@ def test_glob_many_open_files(self):
382383
for it in iters:
383384
self.assertEqual(next(it), p)
384385

386+
def test_glob0(self):
387+
with self.assertWarns(DeprecationWarning):
388+
glob.glob0(self.tempdir, 'a')
389+
390+
with warnings.catch_warnings():
391+
warnings.simplefilter('ignore')
392+
eq = self.assertSequencesEqual_noorder
393+
eq(glob.glob0(self.tempdir, 'a'), ['a'])
394+
eq(glob.glob0(self.tempdir, '.bb'), ['.bb'])
395+
eq(glob.glob0(self.tempdir, '.b*'), [])
396+
eq(glob.glob0(self.tempdir, 'b'), [])
397+
eq(glob.glob0(self.tempdir, '?'), [])
398+
eq(glob.glob0(self.tempdir, '*a'), [])
399+
eq(glob.glob0(self.tempdir, 'a*'), [])
400+
401+
def test_glob1(self):
402+
with self.assertWarns(DeprecationWarning):
403+
glob.glob1(self.tempdir, 'a')
404+
405+
with warnings.catch_warnings():
406+
warnings.simplefilter('ignore')
407+
eq = self.assertSequencesEqual_noorder
408+
eq(glob.glob1(self.tempdir, 'a'), ['a'])
409+
eq(glob.glob1(self.tempdir, '.bb'), ['.bb'])
410+
eq(glob.glob1(self.tempdir, '.b*'), ['.bb'])
411+
eq(glob.glob1(self.tempdir, 'b'), [])
412+
eq(glob.glob1(self.tempdir, '?'), ['a'])
413+
eq(glob.glob1(self.tempdir, '*a'), ['a', 'aaa'])
414+
eq(glob.glob1(self.tempdir, 'a*'), ['a', 'aaa', 'aab'])
415+
385416
def test_translate_matching(self):
386417
match = re.compile(glob.translate('*')).match
387418
self.assertIsNotNone(match('foo'))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecate undocumented :func:`!glob.glob0` and :func:`!glob.glob1`
2+
functions. Use :func:`glob.glob` and pass a directory to its
3+
*root_dir* argument instead.

0 commit comments

Comments
 (0)