From 654b8d936450d94472e26f0b14a9f8d6d249563a Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Tue, 12 Aug 2025 10:32:53 -0700 Subject: [PATCH 1/5] GH-137562: Fix github-issue number for deallocated objects in cache bug (GH-137614) --- Python/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/gc.c b/Python/gc.c index 03455e88d5eeb17..79c7476f4a9a745 100644 --- a/Python/gc.c +++ b/Python/gc.c @@ -882,7 +882,7 @@ move_legacy_finalizer_reachable(PyGC_Head *finalizers) * to invalidate caches (e.g. by PyType_Modified), that clearing has created * a bug. If the weakref to the subclass is cleared before a finalizer is * called, the cache may not be correctly invalidated. That can lead to - * segfaults since the caches can refer to deallocated objects (GH-91636 + * segfaults since the caches can refer to deallocated objects (GH-135552 * is an example). Now, we delay the clear of weakrefs without callbacks * until *after* finalizers have been executed. That means weakrefs without * callbacks are still usable while finalizers are being executed. From 003bd8cc63279b455a7ca5d783ff3623fd2b3804 Mon Sep 17 00:00:00 2001 From: RafaelWO <38643099+RafaelWO@users.noreply.github.com> Date: Tue, 12 Aug 2025 21:28:27 +0200 Subject: [PATCH 2/5] gh-136672: Docs: Move Enum functions and add examples (GH-136791) * Docs: Move Enum functions and add examples When the `Enum` functions `_add_alias_` and `_add_value_alias_` were added in de6bca956432cc852a4a41e2a2cee9cdacd19f35, the documentation for them was done under `EnumType` instead of `Enum`. This change moves them to the docs of the `Enum` class and adds an example for each function. --------- Co-authored-by: Ethan Furman --- Doc/howto/enum.rst | 4 ++-- Doc/library/enum.rst | 53 ++++++++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst index 6441b7aed1eda8c..7713aede6d564a4 100644 --- a/Doc/howto/enum.rst +++ b/Doc/howto/enum.rst @@ -990,9 +990,9 @@ Supported ``_sunder_`` names from the final class - :meth:`~Enum._generate_next_value_` -- used to get an appropriate value for an enum member; may be overridden -- :meth:`~EnumType._add_alias_` -- adds a new name as an alias to an existing +- :meth:`~Enum._add_alias_` -- adds a new name as an alias to an existing member. -- :meth:`~EnumType._add_value_alias_` -- adds a new value as an alias to an +- :meth:`~Enum._add_value_alias_` -- adds a new value as an alias to an existing member. See `MultiValueEnum`_ for an example. .. note:: diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 2cfc2f4962979f4..8875669ffccc378 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -175,6 +175,10 @@ Data Types final *enum*, as well as creating the enum members, properly handling duplicates, providing iteration over the enum class, etc. + .. versionadded:: 3.11 + + Before 3.11 ``EnumType`` was called ``EnumMeta``, which is still available as an alias. + .. method:: EnumType.__call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None) This method is called in two different ways: @@ -206,7 +210,7 @@ Data Types >>> Color.RED.value in Color True - .. versionchanged:: 3.12 + .. versionchanged:: 3.12 Before Python 3.12, a ``TypeError`` is raised if a non-Enum-member is used in a containment check. @@ -251,20 +255,6 @@ Data Types >>> list(reversed(Color)) [, , ] - .. method:: EnumType._add_alias_ - - Adds a new name as an alias to an existing member. Raises a - :exc:`NameError` if the name is already assigned to a different member. - - .. method:: EnumType._add_value_alias_ - - Adds a new value as an alias to an existing member. Raises a - :exc:`ValueError` if the value is already linked with a different member. - - .. versionadded:: 3.11 - - Before 3.11 ``EnumType`` was called ``EnumMeta``, which is still available as an alias. - .. class:: Enum @@ -470,6 +460,30 @@ Data Types .. versionchanged:: 3.12 Added :ref:`enum-dataclass-support` + .. method:: Enum._add_alias_ + + Adds a new name as an alias to an existing member:: + + >>> Color.RED._add_alias_("ERROR") + >>> Color.ERROR + + + Raises a :exc:`NameError` if the name is already assigned to a different member. + + .. versionadded:: 3.13 + + .. method:: Enum._add_value_alias_ + + Adds a new value as an alias to an existing member:: + + >>> Color.RED._add_value_alias_(42) + >>> Color(42) + + + Raises a :exc:`ValueError` if the value is already linked with a different member. + + .. versionadded:: 3.13 + .. class:: IntEnum @@ -879,10 +893,6 @@ Once all the members are created it is no longer used. Supported ``_sunder_`` names """""""""""""""""""""""""""" -- :meth:`~EnumType._add_alias_` -- adds a new name as an alias to an existing - member. -- :meth:`~EnumType._add_value_alias_` -- adds a new value as an alias to an - existing member. - :attr:`~Enum._name_` -- name of the member - :attr:`~Enum._value_` -- value of the member; can be set in ``__new__`` - :meth:`~Enum._missing_` -- a lookup function used when a value is not found; @@ -903,6 +913,11 @@ Supported ``_sunder_`` names For :class:`Flag` classes the next value chosen will be the next highest power-of-two. +- :meth:`~Enum._add_alias_` -- adds a new name as an alias to an existing + member. +- :meth:`~Enum._add_value_alias_` -- adds a new value as an alias to an + existing member. + - While ``_sunder_`` names are generally reserved for the further development of the :class:`Enum` class and can not be used, some are explicitly allowed: From 6baf5524847ef181e901ea5d04d4131132c5a7d5 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 12 Aug 2025 21:17:35 +0100 Subject: [PATCH 3/5] GH-137623: Begin enforcing docstring length in Argument Clinic (#137624) --- Lib/test/clinic.test.c | 20 +- Modules/clinic/posixmodule.c.h | 6 +- Modules/posixmodule.c | 6 +- .../clinic/libclinic/_overlong_docstrings.py | 299 ++++++++++++++++++ Tools/clinic/libclinic/dsl_parser.py | 23 ++ Tools/clinic/libclinic/function.py | 13 + 6 files changed, 355 insertions(+), 12 deletions(-) create mode 100644 Tools/clinic/libclinic/_overlong_docstrings.py diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index dc5b4b27a07f995..b0f7e402469ffc2 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5084,14 +5084,18 @@ Test_an_metho_arg_named_arg_impl(TestObj *self, int arg) Test.__init__ *args: tuple -Varargs init method. For example, nargs is translated to PyTuple_GET_SIZE. +Varargs init method. + +For example, nargs is translated to PyTuple_GET_SIZE. [clinic start generated code]*/ PyDoc_STRVAR(Test___init____doc__, "Test(*args)\n" "--\n" "\n" -"Varargs init method. For example, nargs is translated to PyTuple_GET_SIZE."); +"Varargs init method.\n" +"\n" +"For example, nargs is translated to PyTuple_GET_SIZE."); static int Test___init___impl(TestObj *self, PyObject *args); @@ -5120,21 +5124,25 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs) static int Test___init___impl(TestObj *self, PyObject *args) -/*[clinic end generated code: output=f172425cec373cd6 input=4b8388c4e6baab6f]*/ +/*[clinic end generated code: output=0e5836c40dbc2397 input=a615a4485c0fc3e2]*/ /*[clinic input] @classmethod Test.__new__ *args: tuple -Varargs new method. For example, nargs is translated to PyTuple_GET_SIZE. +Varargs new method. + +For example, nargs is translated to PyTuple_GET_SIZE. [clinic start generated code]*/ PyDoc_STRVAR(Test__doc__, "Test(*args)\n" "--\n" "\n" -"Varargs new method. For example, nargs is translated to PyTuple_GET_SIZE."); +"Varargs new method.\n" +"\n" +"For example, nargs is translated to PyTuple_GET_SIZE."); static PyObject * Test_impl(PyTypeObject *type, PyObject *args); @@ -5162,7 +5170,7 @@ Test(PyTypeObject *type, PyObject *args, PyObject *kwargs) static PyObject * Test_impl(PyTypeObject *type, PyObject *args) -/*[clinic end generated code: output=ee1e8892a67abd4a input=a8259521129cad20]*/ +/*[clinic end generated code: output=e6fba0c8951882fd input=8ce30adb836aeacb]*/ /*[clinic input] diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 8af9e1db781c8ff..df4f802ff0bdc9e 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -215,8 +215,8 @@ PyDoc_STRVAR(os_access__doc__, " NotImplementedError.\n" "\n" "Note that most operations will use the effective uid/gid, therefore this\n" -" routine can be used in a suid/sgid environment to test if the invoking user\n" -" has the specified access to the path."); +" routine can be used in a suid/sgid environment to test if the invoking\n" +" user has the specified access to the path."); #define OS_ACCESS_METHODDEF \ {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__}, @@ -13419,4 +13419,4 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #ifndef OS__EMSCRIPTEN_LOG_METHODDEF #define OS__EMSCRIPTEN_LOG_METHODDEF #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ -/*[clinic end generated code: output=b1e2615384347102 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=23de5d098e2dd73f input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b1a80788bd8115c..76dbb84691db1fd 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -3295,15 +3295,15 @@ dir_fd, effective_ids, and follow_symlinks may not be implemented NotImplementedError. Note that most operations will use the effective uid/gid, therefore this - routine can be used in a suid/sgid environment to test if the invoking user - has the specified access to the path. + routine can be used in a suid/sgid environment to test if the invoking + user has the specified access to the path. [clinic start generated code]*/ static int os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks) -/*[clinic end generated code: output=cf84158bc90b1a77 input=3ffe4e650ee3bf20]*/ +/*[clinic end generated code: output=cf84158bc90b1a77 input=c33565f7584b99e4]*/ { int return_value; diff --git a/Tools/clinic/libclinic/_overlong_docstrings.py b/Tools/clinic/libclinic/_overlong_docstrings.py new file mode 100644 index 000000000000000..5ca335fab2875c8 --- /dev/null +++ b/Tools/clinic/libclinic/_overlong_docstrings.py @@ -0,0 +1,299 @@ +OVERLONG_SUMMARY = frozenset(( + # Lib/test/ + 'test_preprocessor_guarded_if_e_or_f', + + # Modules/ + '_abc._abc_init', + '_abc._abc_instancecheck', + '_abc._abc_register', + '_abc._abc_subclasscheck', + '_codecs.lookup', + '_ctypes.byref', + '_curses.can_change_color', + '_curses.is_term_resized', + '_curses.mousemask', + '_curses.reset_prog_mode', + '_curses.reset_shell_mode', + '_curses.termname', + '_curses.window.enclose', + '_functools.reduce', + '_gdbm.gdbm.setdefault', + '_hashlib.HMAC.hexdigest', + '_hashlib.openssl_shake_128', + '_hashlib.openssl_shake_256', + '_hashlib.pbkdf2_hmac', + '_hmac.HMAC.hexdigest', + '_interpreters.is_shareable', + '_io._BufferedIOBase.read1', + '_lzma._decode_filter_properties', + '_remote_debugging.RemoteUnwinder.__init__', + '_remote_debugging.RemoteUnwinder.get_all_awaited_by', + '_remote_debugging.RemoteUnwinder.get_async_stack_trace', + '_socket.inet_aton', + '_sre.SRE_Match.expand', + '_sre.SRE_Match.groupdict', + '_sre.SRE_Pattern.finditer', + '_sre.SRE_Pattern.search', + '_sre.SRE_Pattern.sub', + '_sre.SRE_Pattern.subn', + '_ssl._SSLContext.sni_callback', + '_ssl._SSLSocket.pending', + '_ssl._SSLSocket.sendfile', + '_ssl.get_default_verify_paths', + '_ssl.RAND_status', + '_sysconfig.config_vars', + '_testcapi.make_exception_with_doc', + '_testcapi.VectorCallClass.set_vectorcall', + '_tkinter.getbusywaitinterval', + '_tkinter.setbusywaitinterval', + '_tracemalloc.reset_peak', + '_zstd.get_frame_size', + '_zstd.set_parameter_types', + '_zstd.ZstdDecompressor.decompress', + 'array.array.buffer_info', + 'array.array.frombytes', + 'array.array.fromfile', + 'array.array.tobytes', + 'cmath.isfinite', + 'datetime.datetime.strptime', + 'gc.get_objects', + 'itertools.chain.from_iterable', + 'itertools.combinations_with_replacement.__new__', + 'itertools.cycle.__new__', + 'itertools.starmap.__new__', + 'itertools.takewhile.__new__', + 'math.comb', + 'math.perm', + 'os.getresgid', + 'os.lstat', + 'os.pread', + 'os.pwritev', + 'os.sched_getaffinity', + 'os.sched_rr_get_interval', + 'os.timerfd_gettime', + 'os.timerfd_gettime_ns', + 'os.urandom', + 'os.WIFEXITED', + 'os.WTERMSIG', + 'pwd.getpwall', + 'pyexpat.xmlparser.ExternalEntityParserCreate', + 'pyexpat.xmlparser.GetReparseDeferralEnabled', + 'pyexpat.xmlparser.SetParamEntityParsing', + 'pyexpat.xmlparser.UseForeignDTD', + 'readline.redisplay', + 'signal.set_wakeup_fd', + 'unicodedata.UCD.combining', + 'unicodedata.UCD.decomposition', + 'zoneinfo.ZoneInfo.dst', + 'zoneinfo.ZoneInfo.tzname', + 'zoneinfo.ZoneInfo.utcoffset', + + # Objects/ + 'B.zfill', + 'bytearray.count', + 'bytearray.endswith', + 'bytearray.extend', + 'bytearray.find', + 'bytearray.index', + 'bytearray.maketrans', + 'bytearray.rfind', + 'bytearray.rindex', + 'bytearray.rsplit', + 'bytearray.split', + 'bytearray.splitlines', + 'bytearray.startswith', + 'bytes.count', + 'bytes.endswith', + 'bytes.find', + 'bytes.index', + 'bytes.maketrans', + 'bytes.rfind', + 'bytes.rindex', + 'bytes.startswith', + 'code.replace', + 'complex.conjugate', + 'dict.pop', + 'float.as_integer_ratio', + 'frame.f_trace', + 'int.bit_count', + 'OrderedDict.fromkeys', + 'OrderedDict.pop', + 'set.symmetric_difference_update', + 'str.count', + 'str.endswith', + 'str.find', + 'str.index', + 'str.isprintable', + 'str.rfind', + 'str.rindex', + 'str.rsplit', + 'str.split', + 'str.startswith', + 'str.strip', + 'str.swapcase', + 'str.zfill', + + # PC/ + 'msvcrt.kbhit', + + # Python/ + '_jit.is_active', + '_jit.is_available', + '_jit.is_enabled', + 'marshal.dumps', + 'sys._current_exceptions', + 'sys._setprofileallthreads', + 'sys._settraceallthreads', +)) + +OVERLONG_BODY = frozenset(( + # Modules/ + '_bz2.BZ2Decompressor.decompress', + '_curses.color_content', + '_curses.flash', + '_curses.longname', + '_curses.resize_term', + '_curses.use_env', + '_curses.window.border', + '_curses.window.derwin', + '_curses.window.getch', + '_curses.window.getkey', + '_curses.window.inch', + '_curses.window.insch', + '_curses.window.insnstr', + '_curses.window.is_linetouched', + '_curses.window.noutrefresh', + '_curses.window.overlay', + '_curses.window.overwrite', + '_curses.window.refresh', + '_curses.window.scroll', + '_curses.window.subwin', + '_curses.window.touchline', + '_curses_panel.panel.hide', + '_functools.reduce', + '_hashlib.HMAC.hexdigest', + '_hmac.HMAC.hexdigest', + '_interpreters.capture_exception', + '_io._IOBase.seek', + '_io._TextIOBase.detach', + '_io.FileIO.read', + '_io.FileIO.readall', + '_io.FileIO.seek', + '_io.open', + '_io.open_code', + '_lzma.LZMADecompressor.decompress', + '_multibytecodec.MultibyteCodec.decode', + '_multibytecodec.MultibyteCodec.encode', + '_posixsubprocess.fork_exec', + '_remote_debugging.RemoteUnwinder.__init__', + '_remote_debugging.RemoteUnwinder.get_all_awaited_by', + '_remote_debugging.RemoteUnwinder.get_async_stack_trace', + '_remote_debugging.RemoteUnwinder.get_stack_trace', + '_socket.socket.send', + '_sqlite3.Blob.read', + '_sqlite3.Blob.seek', + '_sqlite3.Blob.write', + '_sqlite3.Connection.deserialize', + '_sqlite3.Connection.serialize', + '_sqlite3.Connection.set_progress_handler', + '_sqlite3.Connection.setlimit', + '_ssl._SSLContext.sni_callback', + '_ssl._SSLSocket.context', + '_ssl._SSLSocket.get_channel_binding', + '_ssl._SSLSocket.sendfile', + '_tkinter.setbusywaitinterval', + '_zstd.ZstdCompressor.compress', + '_zstd.ZstdCompressor.flush', + '_zstd.ZstdCompressor.set_pledged_input_size', + '_zstd.ZstdDecompressor.__new__', + '_zstd.ZstdDecompressor.decompress', + '_zstd.ZstdDecompressor.unused_data', + '_zstd.ZstdDict.__new__', + '_zstd.ZstdDict.as_digested_dict', + '_zstd.ZstdDict.as_prefix', + '_zstd.ZstdDict.as_undigested_dict', + 'array.array.byteswap', + 'array.array.fromunicode', + 'array.array.tounicode', + 'binascii.a2b_base64', + 'cmath.isclose', + 'datetime.date.fromtimestamp', + 'datetime.datetime.fromtimestamp', + 'datetime.time.strftime', + 'fcntl.ioctl', + 'fcntl.lockf', + 'gc.freeze', + 'itertools.combinations_with_replacement.__new__', + 'math.nextafter', + 'os.fspath', + 'os.link', + 'os.listdir', + 'os.listxattr', + 'os.lseek', + 'os.mknod', + 'os.preadv', + 'os.pwritev', + 'os.readinto', + 'os.rename', + 'os.replace', + 'os.setxattr', + 'pyexpat.xmlparser.GetInputContext', + 'pyexpat.xmlparser.UseForeignDTD', + 'select.devpoll', + 'select.poll', + 'select.select', + 'signal.setitimer', + 'signal.signal', + 'termios.tcsetwinsize', + 'zlib.Decompress.decompress', + 'zlib.ZlibDecompressor.decompress', + + # Objects/ + 'bytearray.maketrans', + 'bytearray.partition', + 'bytearray.replace', + 'bytearray.rpartition', + 'bytearray.rsplit', + 'bytearray.splitlines', + 'bytearray.strip', + 'bytes.maketrans', + 'bytes.partition', + 'bytes.replace', + 'bytes.rpartition', + 'bytes.rsplit', + 'bytes.splitlines', + 'bytes.strip', + 'float.__getformat__', + 'list.sort', + 'memoryview.tobytes', + 'str.capitalize', + 'str.isalnum', + 'str.isalpha', + 'str.isdecimal', + 'str.isdigit', + 'str.isidentifier', + 'str.islower', + 'str.isnumeric', + 'str.isspace', + 'str.isupper', + 'str.join', + 'str.partition', + 'str.removeprefix', + 'str.replace', + 'str.rpartition', + 'str.splitlines', + 'str.title', + 'str.translate', + + # PC/ + '_wmi.exec_query', + + # Python/ + '__import__', + '_contextvars.ContextVar.get', + '_contextvars.ContextVar.reset', + '_contextvars.ContextVar.set', + '_imp.acquire_lock', + 'marshal.dumps', + 'sys._stats_dump', +)) diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index eca41531f7c8e9b..58430df6173fd06 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -14,6 +14,7 @@ from libclinic import ( ClinicError, VersionTuple, fail, warn, unspecified, unknown, NULL) +from libclinic._overlong_docstrings import OVERLONG_SUMMARY, OVERLONG_BODY from libclinic.function import ( Module, Class, Function, Parameter, FunctionKind, @@ -1515,6 +1516,28 @@ def format_docstring(self) -> str: # between it and the {parameters} we're about to add. lines.append('') + # Fail if the summary line is too long. + # Warn if any of the body lines are too long. + # Existing violations are recorded in OVERLONG_{SUMMARY,BODY}. + max_width = f.docstring_line_width + summary_len = len(lines[0]) + max_body = max(map(len, lines[1:])) + if summary_len > max_width: + if f.full_name not in OVERLONG_SUMMARY: + fail(f"Summary line for {f.full_name!r} is too long!\n" + f"The summary line must be no longer than {max_width} characters.") + else: + if f.full_name in OVERLONG_SUMMARY: + warn(f"Remove {f.full_name!r} from OVERLONG_SUMMARY!\n") + + if max_body > max_width: + if f.full_name not in OVERLONG_BODY: + warn(f"Docstring lines for {f.full_name!r} are too long!\n" + f"Lines should be no longer than {max_width} characters.") + else: + if f.full_name in OVERLONG_BODY: + warn(f"Remove {f.full_name!r} from OVERLONG_BODY!\n") + parameters_marker_count = len(f.docstring.split('{parameters}')) - 1 if parameters_marker_count > 1: fail('You may not specify {parameters} more than once in a docstring!') diff --git a/Tools/clinic/libclinic/function.py b/Tools/clinic/libclinic/function.py index e80e2f5f13f648e..4280af0c4c9b495 100644 --- a/Tools/clinic/libclinic/function.py +++ b/Tools/clinic/libclinic/function.py @@ -167,6 +167,19 @@ def methoddef_flags(self) -> str | None: flags.append('METH_COEXIST') return '|'.join(flags) + @property + def docstring_line_width(self) -> int: + """Return the maximum line width for docstring lines. + + Pydoc adds indentation when displaying functions and methods. + To keep the total width of within 80 characters, we use a + maximum of 76 characters for global functions and classes, + and 72 characters for methods. + """ + if self.cls is not None and not self.kind.new_or_init: + return 72 + return 76 + def __repr__(self) -> str: return f'' From e93dca72232efe6d5cf2d52ea6dd3967ff61360b Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 13 Aug 2025 01:01:50 +0300 Subject: [PATCH 4/5] gh-133403: Run `mypy` on `Tools/build/mypy.ini` changes (#137692) --- .github/workflows/mypy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index dc6367150329698..0413d5f905d771d 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -13,6 +13,7 @@ on: - "Lib/test/libregrtest/**" - "Lib/tomllib/**" - "Misc/mypy/**" + - "Tools/build/mypy.ini" - "Tools/build/check_extension_modules.py" - "Tools/build/compute-changes.py" - "Tools/build/deepfreeze.py" From 797c2c33e181badc053f76c58b49e01ccc9a2163 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 12 Aug 2025 23:28:38 +0100 Subject: [PATCH 5/5] GH-137630: Argument Clinic: Reduce use of 'as' for renaming in ``_interpretersmodule.c`` (#137680) --- Modules/_interpretersmodule.c | 25 ++++++++++++------------- Modules/clinic/_interpretersmodule.c.h | 25 ++++++++++++------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Modules/_interpretersmodule.c b/Modules/_interpretersmodule.c index c7a3d54a0b9a520..dc79cb088f94e59 100644 --- a/Modules/_interpretersmodule.c +++ b/Modules/_interpretersmodule.c @@ -1276,8 +1276,8 @@ _interpreters_run_func_impl(PyObject *module, PyObject *id, PyObject *func, _interpreters.call id: object callable: object - args as args_obj: object(subclass_of='&PyTuple_Type', c_default='NULL') = () - kwargs as kwargs_obj: object(subclass_of='&PyDict_Type', c_default='NULL') = {} + args: object(subclass_of='&PyTuple_Type', c_default='NULL') = () + kwargs: object(subclass_of='&PyDict_Type', c_default='NULL') = {} * preserve_exc: bool = False restrict as restricted: bool = False @@ -1289,9 +1289,9 @@ Pass the given args and kwargs, if possible. static PyObject * _interpreters_call_impl(PyObject *module, PyObject *id, PyObject *callable, - PyObject *args_obj, PyObject *kwargs_obj, - int preserve_exc, int restricted) -/*[clinic end generated code: output=983ee27b3c43f6ef input=77590fdb3f519d65]*/ + PyObject *args, PyObject *kwargs, int preserve_exc, + int restricted) +/*[clinic end generated code: output=b7a4a27d72df3ebc input=b026d0b212a575e6]*/ { PyThreadState *tstate = _PyThreadState_GET(); int reqready = 1; @@ -1302,7 +1302,7 @@ _interpreters_call_impl(PyObject *module, PyObject *id, PyObject *callable, } struct interp_call call = {0}; - if (_interp_call_pack(tstate, &call, callable, args_obj, kwargs_obj) < 0) { + if (_interp_call_pack(tstate, &call, callable, args, kwargs) < 0) { return NULL; } @@ -1376,7 +1376,7 @@ _interpreters_is_running_impl(PyObject *module, PyObject *id, int restricted) /*[clinic input] _interpreters.get_config - id as idobj: object + id: object * restrict as restricted: bool = False @@ -1384,17 +1384,16 @@ Return a representation of the config used to initialize the interpreter. [clinic start generated code]*/ static PyObject * -_interpreters_get_config_impl(PyObject *module, PyObject *idobj, - int restricted) -/*[clinic end generated code: output=63f81d35c2fe1387 input=aa38d50f534eb3c5]*/ +_interpreters_get_config_impl(PyObject *module, PyObject *id, int restricted) +/*[clinic end generated code: output=56773353b9b7224a input=59519a01c22d96d1]*/ { - if (idobj == Py_None) { - idobj = NULL; + if (id == Py_None) { + id = NULL; } int reqready = 0; PyInterpreterState *interp = \ - resolve_interp(idobj, restricted, reqready, "get the config of"); + resolve_interp(id, restricted, reqready, "get the config of"); if (interp == NULL) { return NULL; } diff --git a/Modules/clinic/_interpretersmodule.c.h b/Modules/clinic/_interpretersmodule.c.h index a8f0d3df8908dc1..d70ffcea527895a 100644 --- a/Modules/clinic/_interpretersmodule.c.h +++ b/Modules/clinic/_interpretersmodule.c.h @@ -639,8 +639,8 @@ PyDoc_STRVAR(_interpreters_call__doc__, static PyObject * _interpreters_call_impl(PyObject *module, PyObject *id, PyObject *callable, - PyObject *args_obj, PyObject *kwargs_obj, - int preserve_exc, int restricted); + PyObject *args, PyObject *kwargs, int preserve_exc, + int restricted); static PyObject * _interpreters_call(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) @@ -677,8 +677,8 @@ _interpreters_call(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; PyObject *id; PyObject *callable; - PyObject *args_obj = NULL; - PyObject *kwargs_obj = NULL; + PyObject *__clinic_args = NULL; + PyObject *__clinic_kwargs = NULL; int preserve_exc = 0; int restricted = 0; @@ -697,7 +697,7 @@ _interpreters_call(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py _PyArg_BadArgument("call", "argument 'args'", "tuple", args[2]); goto exit; } - args_obj = args[2]; + __clinic_args = args[2]; if (!--noptargs) { goto skip_optional_pos; } @@ -707,7 +707,7 @@ _interpreters_call(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py _PyArg_BadArgument("call", "argument 'kwargs'", "dict", args[3]); goto exit; } - kwargs_obj = args[3]; + __clinic_kwargs = args[3]; if (!--noptargs) { goto skip_optional_pos; } @@ -730,7 +730,7 @@ _interpreters_call(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py goto exit; } skip_optional_kwonly: - return_value = _interpreters_call_impl(module, id, callable, args_obj, kwargs_obj, preserve_exc, restricted); + return_value = _interpreters_call_impl(module, id, callable, __clinic_args, __clinic_kwargs, preserve_exc, restricted); exit: return return_value; @@ -872,8 +872,7 @@ PyDoc_STRVAR(_interpreters_get_config__doc__, {"get_config", _PyCFunction_CAST(_interpreters_get_config), METH_FASTCALL|METH_KEYWORDS, _interpreters_get_config__doc__}, static PyObject * -_interpreters_get_config_impl(PyObject *module, PyObject *idobj, - int restricted); +_interpreters_get_config_impl(PyObject *module, PyObject *id, int restricted); static PyObject * _interpreters_get_config(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) @@ -908,7 +907,7 @@ _interpreters_get_config(PyObject *module, PyObject *const *args, Py_ssize_t nar #undef KWTUPLE PyObject *argsbuf[2]; Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; - PyObject *idobj; + PyObject *id; int restricted = 0; args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, @@ -916,7 +915,7 @@ _interpreters_get_config(PyObject *module, PyObject *const *args, Py_ssize_t nar if (!args) { goto exit; } - idobj = args[0]; + id = args[0]; if (!noptargs) { goto skip_optional_kwonly; } @@ -925,7 +924,7 @@ _interpreters_get_config(PyObject *module, PyObject *const *args, Py_ssize_t nar goto exit; } skip_optional_kwonly: - return_value = _interpreters_get_config_impl(module, idobj, restricted); + return_value = _interpreters_get_config_impl(module, id, restricted); exit: return return_value; @@ -1199,4 +1198,4 @@ _interpreters_capture_exception(PyObject *module, PyObject *const *args, Py_ssiz exit: return return_value; } -/*[clinic end generated code: output=cf3f54caaa2dd6a2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c80f73761f860f6c input=a9049054013a1b77]*/