https://github.com/python/cpython/commit/dac4589726952be873df13f41bea24cc6f9da6b1
commit: dac4589726952be873df13f41bea24cc6f9da6b1
branch: main
author: Brett Cannon <[email protected]>
committer: brettcannon <[email protected]>
date: 2025-12-11T09:55:47-08:00
summary:
GH-142203: Remove the `debug_override` parameter from
`packaging.util.cache_from_source()` (GH-142204)
files:
A Misc/NEWS.d/next/Library/2025-12-02-14-52-51.gh-issue-142203.ofWOvV.rst
M Doc/library/importlib.rst
M Lib/importlib/_bootstrap_external.py
M Lib/test/test_importlib/test_util.py
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 34130f9be67e7e..b851b929b7e2fb 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -1300,7 +1300,7 @@ an :term:`importer`.
.. versionadded:: 3.4
-.. function:: cache_from_source(path, debug_override=None, *,
optimization=None)
+.. function:: cache_from_source(path, *, optimization=None)
Return the :pep:`3147`/:pep:`488` path to the byte-compiled file associated
with the source *path*. For example, if *path* is ``/foo/bar/baz.py`` the
return
@@ -1319,12 +1319,6 @@ an :term:`importer`.
``/foo/bar/__pycache__/baz.cpython-32.opt-2.pyc``. The string representation
of *optimization* can only be alphanumeric, else :exc:`ValueError` is
raised.
- The *debug_override* parameter is deprecated and can be used to override
- the system's value for ``__debug__``. A ``True`` value is the equivalent of
- setting *optimization* to the empty string. A ``False`` value is the same as
- setting *optimization* to ``1``. If both *debug_override* an *optimization*
- are not ``None`` then :exc:`TypeError` is raised.
-
.. versionadded:: 3.4
.. versionchanged:: 3.5
@@ -1334,6 +1328,9 @@ an :term:`importer`.
.. versionchanged:: 3.6
Accepts a :term:`path-like object`.
+ .. versionchanged:: 3.15
+ The *debug_override* parameter was removed.
+
.. function:: source_from_cache(path)
diff --git a/Lib/importlib/_bootstrap_external.py
b/Lib/importlib/_bootstrap_external.py
index 332dc1c5a4fc8f..9d289674357b44 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -236,7 +236,7 @@ def _write_atomic(path, data, mode=0o666):
# Deprecated.
DEBUG_BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES = BYTECODE_SUFFIXES
-def cache_from_source(path, debug_override=None, *, optimization=None):
+def cache_from_source(path, *, optimization=None):
"""Given the path to a .py file, return the path to its .pyc file.
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):
of the argument is taken and verified to be alphanumeric (else ValueError
is raised).
- The debug_override parameter is deprecated. If debug_override is not None,
- a True value is the same as setting 'optimization' to the empty string
- while a False value is equivalent to setting 'optimization' to '1'.
-
If sys.implementation.cache_tag is None then NotImplementedError is raised.
"""
- if debug_override is not None:
- _warnings.warn('the debug_override parameter is deprecated; use '
- "'optimization' instead", DeprecationWarning)
- if optimization is not None:
- message = 'debug_override or optimization must be set to None'
- raise TypeError(message)
- optimization = '' if debug_override else 1
path = _os.fspath(path)
head, tail = _path_split(path)
base, sep, rest = tail.rpartition('.')
diff --git a/Lib/test/test_importlib/test_util.py
b/Lib/test/test_importlib/test_util.py
index 0adab8d14e0452..a49e360d10fb7c 100644
--- a/Lib/test/test_importlib/test_util.py
+++ b/Lib/test/test_importlib/test_util.py
@@ -359,47 +359,12 @@ def test_cache_from_source_no_dot(self):
self.assertEqual(self.util.cache_from_source(path, optimization=''),
expect)
- def test_cache_from_source_debug_override(self):
- # Given the path to a .py file, return the path to its PEP 3147/PEP 488
- # defined .pyc file (i.e. under __pycache__).
- path = os.path.join('foo', 'bar', 'baz', 'qux.py')
- with warnings.catch_warnings():
- warnings.simplefilter('ignore')
- self.assertEqual(self.util.cache_from_source(path, False),
- self.util.cache_from_source(path, optimization=1))
- self.assertEqual(self.util.cache_from_source(path, True),
- self.util.cache_from_source(path,
optimization=''))
- with warnings.catch_warnings():
- warnings.simplefilter('error')
- with self.assertRaises(DeprecationWarning):
- self.util.cache_from_source(path, False)
- with self.assertRaises(DeprecationWarning):
- self.util.cache_from_source(path, True)
-
def test_cache_from_source_cwd(self):
path = 'foo.py'
expect = os.path.join('__pycache__', 'foo.{}.pyc'.format(self.tag))
self.assertEqual(self.util.cache_from_source(path, optimization=''),
expect)
- def test_cache_from_source_override(self):
- # When debug_override is not None, it can be any true-ish or false-ish
- # value.
- path = os.path.join('foo', 'bar', 'baz.py')
- # However if the bool-ishness can't be determined, the exception
- # propagates.
- class Bearish:
- def __bool__(self): raise RuntimeError
- with warnings.catch_warnings():
- warnings.simplefilter('ignore')
- self.assertEqual(self.util.cache_from_source(path, []),
- self.util.cache_from_source(path, optimization=1))
- self.assertEqual(self.util.cache_from_source(path, [17]),
- self.util.cache_from_source(path,
optimization=''))
- with self.assertRaises(RuntimeError):
- self.util.cache_from_source('/foo/bar/baz.py', Bearish())
-
-
def test_cache_from_source_optimization_empty_string(self):
# Setting 'optimization' to '' leads to no optimization tag (PEP 488).
path = 'foo.py'
diff --git
a/Misc/NEWS.d/next/Library/2025-12-02-14-52-51.gh-issue-142203.ofWOvV.rst
b/Misc/NEWS.d/next/Library/2025-12-02-14-52-51.gh-issue-142203.ofWOvV.rst
new file mode 100644
index 00000000000000..87e5870ddd6389
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-12-02-14-52-51.gh-issue-142203.ofWOvV.rst
@@ -0,0 +1,3 @@
+Remove the *debug_override* parameter from
+:func:`importlib.util.cache_from_source` which has been deprecated since
+Python 3.5.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]