🌐 AI搜索 & 代理 主页
Skip to content

Commit dac4589

Browse files
authored
GH-142203: Remove the debug_override parameter from packaging.util.cache_from_source() (GH-142204)
1 parent 387f88c commit dac4589

File tree

4 files changed

+8
-54
lines changed

4 files changed

+8
-54
lines changed

Doc/library/importlib.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ an :term:`importer`.
13001300

13011301
.. versionadded:: 3.4
13021302

1303-
.. function:: cache_from_source(path, debug_override=None, *, optimization=None)
1303+
.. function:: cache_from_source(path, *, optimization=None)
13041304

13051305
Return the :pep:`3147`/:pep:`488` path to the byte-compiled file associated
13061306
with the source *path*. For example, if *path* is ``/foo/bar/baz.py`` the return
@@ -1319,12 +1319,6 @@ an :term:`importer`.
13191319
``/foo/bar/__pycache__/baz.cpython-32.opt-2.pyc``. The string representation
13201320
of *optimization* can only be alphanumeric, else :exc:`ValueError` is raised.
13211321

1322-
The *debug_override* parameter is deprecated and can be used to override
1323-
the system's value for ``__debug__``. A ``True`` value is the equivalent of
1324-
setting *optimization* to the empty string. A ``False`` value is the same as
1325-
setting *optimization* to ``1``. If both *debug_override* an *optimization*
1326-
are not ``None`` then :exc:`TypeError` is raised.
1327-
13281322
.. versionadded:: 3.4
13291323

13301324
.. versionchanged:: 3.5
@@ -1334,6 +1328,9 @@ an :term:`importer`.
13341328
.. versionchanged:: 3.6
13351329
Accepts a :term:`path-like object`.
13361330

1331+
.. versionchanged:: 3.15
1332+
The *debug_override* parameter was removed.
1333+
13371334

13381335
.. function:: source_from_cache(path)
13391336

Lib/importlib/_bootstrap_external.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def _write_atomic(path, data, mode=0o666):
236236
# Deprecated.
237237
DEBUG_BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES = BYTECODE_SUFFIXES
238238

239-
def cache_from_source(path, debug_override=None, *, optimization=None):
239+
def cache_from_source(path, *, optimization=None):
240240
"""Given the path to a .py file, return the path to its .pyc file.
241241
242242
The .py file does not need to exist; this simply returns the path to the
@@ -247,20 +247,9 @@ def cache_from_source(path, debug_override=None, *, optimization=None):
247247
of the argument is taken and verified to be alphanumeric (else ValueError
248248
is raised).
249249
250-
The debug_override parameter is deprecated. If debug_override is not None,
251-
a True value is the same as setting 'optimization' to the empty string
252-
while a False value is equivalent to setting 'optimization' to '1'.
253-
254250
If sys.implementation.cache_tag is None then NotImplementedError is raised.
255251
256252
"""
257-
if debug_override is not None:
258-
_warnings.warn('the debug_override parameter is deprecated; use '
259-
"'optimization' instead", DeprecationWarning)
260-
if optimization is not None:
261-
message = 'debug_override or optimization must be set to None'
262-
raise TypeError(message)
263-
optimization = '' if debug_override else 1
264253
path = _os.fspath(path)
265254
head, tail = _path_split(path)
266255
base, sep, rest = tail.rpartition('.')

Lib/test/test_importlib/test_util.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -359,47 +359,12 @@ def test_cache_from_source_no_dot(self):
359359
self.assertEqual(self.util.cache_from_source(path, optimization=''),
360360
expect)
361361

362-
def test_cache_from_source_debug_override(self):
363-
# Given the path to a .py file, return the path to its PEP 3147/PEP 488
364-
# defined .pyc file (i.e. under __pycache__).
365-
path = os.path.join('foo', 'bar', 'baz', 'qux.py')
366-
with warnings.catch_warnings():
367-
warnings.simplefilter('ignore')
368-
self.assertEqual(self.util.cache_from_source(path, False),
369-
self.util.cache_from_source(path, optimization=1))
370-
self.assertEqual(self.util.cache_from_source(path, True),
371-
self.util.cache_from_source(path, optimization=''))
372-
with warnings.catch_warnings():
373-
warnings.simplefilter('error')
374-
with self.assertRaises(DeprecationWarning):
375-
self.util.cache_from_source(path, False)
376-
with self.assertRaises(DeprecationWarning):
377-
self.util.cache_from_source(path, True)
378-
379362
def test_cache_from_source_cwd(self):
380363
path = 'foo.py'
381364
expect = os.path.join('__pycache__', 'foo.{}.pyc'.format(self.tag))
382365
self.assertEqual(self.util.cache_from_source(path, optimization=''),
383366
expect)
384367

385-
def test_cache_from_source_override(self):
386-
# When debug_override is not None, it can be any true-ish or false-ish
387-
# value.
388-
path = os.path.join('foo', 'bar', 'baz.py')
389-
# However if the bool-ishness can't be determined, the exception
390-
# propagates.
391-
class Bearish:
392-
def __bool__(self): raise RuntimeError
393-
with warnings.catch_warnings():
394-
warnings.simplefilter('ignore')
395-
self.assertEqual(self.util.cache_from_source(path, []),
396-
self.util.cache_from_source(path, optimization=1))
397-
self.assertEqual(self.util.cache_from_source(path, [17]),
398-
self.util.cache_from_source(path, optimization=''))
399-
with self.assertRaises(RuntimeError):
400-
self.util.cache_from_source('/foo/bar/baz.py', Bearish())
401-
402-
403368
def test_cache_from_source_optimization_empty_string(self):
404369
# Setting 'optimization' to '' leads to no optimization tag (PEP 488).
405370
path = 'foo.py'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove the *debug_override* parameter from
2+
:func:`importlib.util.cache_from_source` which has been deprecated since
3+
Python 3.5.

0 commit comments

Comments
 (0)