]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-142203: Remove the `debug_override` parameter from `packaging.util.cache_from_sour...
authorBrett Cannon <brett@python.org>
Thu, 11 Dec 2025 17:55:47 +0000 (09:55 -0800)
committerGitHub <noreply@github.com>
Thu, 11 Dec 2025 17:55:47 +0000 (09:55 -0800)
Doc/library/importlib.rst
Lib/importlib/_bootstrap_external.py
Lib/test/test_importlib/test_util.py
Misc/NEWS.d/next/Library/2025-12-02-14-52-51.gh-issue-142203.ofWOvV.rst [new file with mode: 0644]

index 34130f9be67e7eb0e3dce59e41324f9a68557fe1..b851b929b7e2fbd778325d13a3e87d5bd6494b59 100644 (file)
@@ -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)
 
index 332dc1c5a4fc8f2e0b5b81497371a6d98c0498c8..9d289674357b44cefebdcd9af2cdc88079d69381 100644 (file)
@@ -236,7 +236,7 @@ BYTECODE_SUFFIXES = ['.pyc']
 # 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('.')
index 0adab8d14e04523a59d606b4300406440164e761..a49e360d10fb7c01759f9f590a2b3160c0a2709c 100644 (file)
@@ -359,47 +359,12 @@ class PEP3147Tests:
         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 (file)
index 0000000..87e5870
--- /dev/null
@@ -0,0 +1,3 @@
+Remove the *debug_override* parameter from
+:func:`importlib.util.cache_from_source` which has been deprecated since
+Python 3.5.