From b7e305b2cc228764a452e223fe475eec0e3a5af4 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Wed, 1 Jan 2025 12:52:57 +0200 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/functools.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Lib/functools.py b/Lib/functools.py index 2ea97b7009f15b..67ebcc032c7031 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -1118,8 +1118,8 @@ def __get__(self, instance, owner=None): __class_getitem__ = classmethod(GenericAlias) -def _warn_kwargs(func): - @wraps(func) +def _warn_python_reduce_kwargs(py_reduce): + @wraps(py_reduce) def wrapper(*args, **kwargs): if 'function' in kwargs or 'sequence' in kwargs: import os @@ -1131,14 +1131,16 @@ def wrapper(*args, **kwargs): 'forbidden in Python 3.16.', DeprecationWarning, skip_file_prefixes=(os.path.dirname(__file__),)) - return func(*args, **kwargs) + return py_reduce(*args, **kwargs) return wrapper -reduce = _warn_kwargs(reduce) +reduce = _warn_python_reduce_kwargs(reduce) +del _warn_python_reduce_kwargs -# This import has been moved here due to gh-121676 -# In Python3.16 _warn_kwargs should be removed, and this -# import should be moved right after the reduce definition +# The import of the C accelerated version of reduce() has been moved +# here due to gh-121676. In Python 3.16, _warn_python_reduce_kwargs() +# should be removed and the import block should be moved back right +# after the definition of reduce(). try: from _functools import reduce except ImportError: