summaryrefslogtreecommitdiffstats
path: root/Python/clinic
Commit message (Collapse)AuthorAgeFilesLines
* gh-135801: Add the module parameter to compile() etc (GH-139652)Serhiy Storchaka2025-11-131-9/+17
| | | | | | | Many functions related to compiling or parsing Python code, such as compile(), ast.parse(), symtable.symtable(), and importlib.abc.InspectLoader.source_to_code() now allow to pass the module name used when filtering syntax warnings.
* gh-111489: Remove _PyTuple_FromArray() alias (#139973)Victor Stinner2025-10-111-3/+2
| | | | Replace _PyTuple_FromArray() with PyTuple_FromArray(). Remove pycore_tuple.h includes.
* gh-139748: fix leaks in AC error paths when using unicode FS-based ↵Bénédikt Tran2025-10-081-2/+5
| | | | converters (#139765)
* gh-137609: Change names of some positional-only parameters in builtins ↵Serhiy Storchaka2025-08-251-14/+14
| | | | | | (GH-137611) This is for a pair with GH-137610.
* gh-135228: Create __dict__ and __weakref__ descriptors for object (GH-136966)Petr Viktorin2025-08-181-32/+1
| | | | | | | | | | | | | | | | | | | | | | | This partially reverts #137047, keeping the tests for GC collectability of the original class that dataclass adds `__slots__` to. The reference leaks solved there are instead solved by having the `__dict__` & `__weakref__` descriptors not tied to (and referencing) their class. Instead, they're shared between all classes that need them (within an interpreter). The `__objclass__` ol the descriptors is set to `object`, since these descriptors work with *any* object. (The appropriate checks were already made in the get/set code, so the `__objclass__` check was redundant.) The repr of these descriptors (and any others whose `__objclass__` is `object`) now doesn't mention the objclass. This change required adjustment of introspection code that checks `__objclass__` to determine an object's “own” (i.e. not inherited) `__dict__`. Third-party code that does similar introspection of the internals will also need adjusting. Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-137668: Document that ord() supports also bytes and bytearray (GH-137669)Serhiy Storchaka2025-08-131-3/+9
|
* gh-135228: When @dataclass(slots=True) replaces a dataclass, make the ↵Jelle Zijlstra2025-08-121-1/+32
| | | | | | | | | | | | | | | | original class collectible (take 2) (GH-137047) Remove the `__dict__` and `__weakref__` descriptors from the original class when creating a dataclass from it. An interesting hack, but more localized in scope than gh-135230. This may be a breaking change if people intentionally keep the original class around when using `@dataclass(slots=True)`, and then use `__dict__` or `__weakref__` on the original class. Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* GH-133231: Add JIT utilities in sys._jit (GH-133233)Brandt Bucher2025-05-051-1/+85
|
* gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)Neil Schemenauer2025-04-091-0/+21
| | | | | | | | | | | | | | | | | | | | Make `warnings.catch_warnings()` use a context variable for holding the warning filtering state if the `sys.flags.context_aware_warnings` flag is set to true. This makes using the context manager thread-safe in multi-threaded programs. Add the `sys.flags.thread_inherit_context` flag. If true, starting a new thread with `threading.Thread` will use a copy of the context from the caller of `Thread.start()`. Both these flags are set to true by default for the free-threaded build and false for the default build. Move the Python implementation of warnings.py into _py_warnings.py. Make _contextvars a builtin module. Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-131591: Implement PEP 768 (#131937)Pablo Galindo Salgado2025-04-031-1/+99
| | | | Co-authored-by: Ivona Stojanovic <stojanovic.i@hotmail.com> Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
* gh-131525: Cache the result of tuple_hash (#131529)Michael Droettboom2025-03-278-8/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * gh-131525: Cache the result of tuple_hash * Fix debug builds * Add blurb * Fix formatting * Pre-compute empty tuple singleton * Mostly set the cache within tuple_alloc * Fixes for TSAN * Pre-compute empty tuple singleton * Fix for 32-bit platforms * Assert that op != NULL in _PyTuple_RESET_HASH_CACHE * Use FT_ATOMIC_STORE_SSIZE_RELAXED macro * Update Include/internal/pycore_tuple.h Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> * Fix alignment * atomic load * Update Objects/tupleobject.c Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> --------- Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
* gh-128421: add critical section around `traceback.tb_next` (#131322)Kumar Aditya2025-03-201-1/+52
|
* gh-111178: Change Argument Clinic signature for METH_O (#130682)Victor Stinner2025-03-112-2/+41
| | | Use "PyObject*" for METH_O functions to fix an undefined behavior.
* gh-129889: Support context manager protocol by contextvars.Token (#129888)Andrew Svetlov2025-02-121-1/+52
|
* gh-128509: Add `sys._is_immortal` for identifying immortal objects (#128510)Peter Bierma2025-01-311-1/+31
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-111178: Generate correct signature for most self converters (#128447)Erlend E. Aasland2025-01-202-26/+26
|
* gh-128384: Add locking to warnings.py. (gh-128386)Neil Schemenauer2025-01-141-8/+42
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* GH-126833: Dumps graphviz representation of executor graph. (GH-126880)Mark Shannon2024-12-131-1/+57
|
* gh-126579: Adapt sys.audit() to Argument Clinic (GH-126580)Serhiy Storchaka2024-11-081-1/+50
|
* gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords (GH-126564)Serhiy Storchaka2024-11-088-34/+60
| | | | Remove _PyArg_UnpackKeywordsWithVararg. Add comments for integer arguments of _PyArg_UnpackKeywords.
* gh-122943: Remove the object converter for var-positional parameter (GH-126560)Serhiy Storchaka2024-11-081-13/+9
|
* gh-122943: Rework support of var-positional parameter in Argument Clinic ↵Serhiy Storchaka2024-11-071-12/+19
| | | | | | | | | | | | | | | | | | (GH-122945) Move creation of a tuple for var-positional parameter out of _PyArg_UnpackKeywordsWithVararg(). Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords(). Add a new parameter in _PyArg_UnpackKeywords(). The "parameters" and "converters" attributes of ParseArgsCodeGen no longer contain the var-positional parameter. It is now available as the "varpos" attribute. Optimize code generation for var-positional parameter and reuse the same generating code for functions with and without keyword parameters. Add special converters for var-positional parameter. "tuple" represents it as a Python tuple and "array" represents it as a continuous array of PyObject*. "object" is a temporary alias of "tuple".
* gh-116750: Add clear_tool_id function to unregister events and callbacks ↵Tian Gao2024-10-011-1/+28
| | | | (#124568)
* gh-113993: Allow interned strings to be mortal, and fix related issues ↵Petr Viktorin2024-06-211-6/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-120520) * Add an InternalDocs file describing how interning should work and how to use it. * Add internal functions to *explicitly* request what kind of interning is done: - `_PyUnicode_InternMortal` - `_PyUnicode_InternImmortal` - `_PyUnicode_InternStatic` * Switch uses of `PyUnicode_InternInPlace` to those. * Disallow using `_Py_SetImmortal` on strings directly. You should use `_PyUnicode_InternImmortal` instead: - Strings should be interned before immortalization, otherwise you're possibly interning a immortalizing copy. - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in backports, as they are now part of public API and version-specific ABI. * Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery. * Make sure the statically allocated string singletons are unique. This means these sets are now disjoint: - `_Py_ID` - `_Py_STR` (including the empty string) - one-character latin-1 singletons Now, when you intern a singleton, that exact singleton will be interned. * Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic). * Intern `_Py_STR` singletons at startup. * For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup. * Beef up the tests. Cover internal details (marked with `@cpython_only`). * Add lots of assertions Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
* gh-111201: A new Python REPL (GH-111567)Pablo Galindo Salgado2024-05-051-1/+19
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-117514: Add `sys._is_gil_enabled()` function (#118514)Sam Gross2024-05-031-1/+29
| | | | | The function returns `True` or `False` depending on whether the GIL is currently enabled. In the default build, it always returns `True` because the GIL is always enabled.
* gh-105879: Add support for keyword arguments to eval and exec (#105885)Raphael Gaschignard2024-05-021-24/+59
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-117680: make _PyInstructionSequence a PyObject and use it in tests (#117629)Irit Katriel2024-04-171-0/+304
|
* gh-117764: Fix and add signatures for many builtins (GH-117769)Serhiy Storchaka2024-04-122-8/+8
|
* gh-117764: Add signatures for some functions in the sys module (GH-117770)Serhiy Storchaka2024-04-121-5/+29
| | | Use Argument Clinic if possible.
* GH-114695: Add `sys._clear_internal_caches` (GH-115152)Brandt Bucher2024-02-121-1/+19
|
* gh-76763: Make chr() always raising ValueError for out-of-range values ↵Serhiy Storchaka2024-02-101-20/+1
| | | | | | (GH-114882) Previously it raised OverflowError for very large or very small values.
* gh-113626: Add allow_code parameter in marshal functions (GH-113648)Serhiy Storchaka2024-01-161-26/+212
| | | | | Passing allow_code=False prevents serialization and de-serialization of code objects which is incompatible between Python versions.
* bpo-34392: Add sys. _is_interned() (GH-8755)Serhiy Storchaka2023-12-041-1/+35
|
* gh-111089: Revert PyUnicode_AsUTF8() changes (#111833)Victor Stinner2023-11-073-6/+21
| | | | | | | | | | | | | | | | | | | | | * Revert "gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)" This reverts commit d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2. * Revert "gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)" This reverts commit cde1071b2a72e8261ca66053ef61431b7f3a81fd. * Revert "gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)" This reverts commit d731579bfb9a497cfb0076cb6b221058a20088fe. * Revert "gh-111089: Add PyUnicode_AsUTF8() to the limited C API (#111121)" This reverts commit d8f32be5b6a736dc2fc9dca3f1bf176c82fc9b44. * Revert "gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122)" This reverts commit 37e4e20eaa8f27ada926d49e5971fecf0477ad26.
* gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)Victor Stinner2023-11-013-21/+6
| | | | | | | Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove the explicit check for embedded null characters. The change avoids to have to include explicitly <string.h> to get the strlen() function when using a recent version of the limited C API.
* gh-67565: Remove redundant C-contiguity checks (GH-105521)Furkan Onder2023-10-232-10/+2
| | | | Co-authored-by: Stefan Krah <skrah@bytereef.org>
* gh-110964: Remove private _PyArg functions (#110966)Victor Stinner2023-10-179-9/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the following private functions and structures to pycore_modsupport.h internal C API: * _PyArg_BadArgument() * _PyArg_CheckPositional() * _PyArg_NoKeywords() * _PyArg_NoPositional() * _PyArg_ParseStack() * _PyArg_ParseStackAndKeywords() * _PyArg_Parser structure * _PyArg_UnpackKeywords() * _PyArg_UnpackKeywordsWithVararg() * _PyArg_UnpackStack() * _Py_ANY_VARARGS() Changes: * Python/getargs.h now includes pycore_modsupport.h to export functions. * clinic.py now adds pycore_modsupport.h when one of these functions is used. * Add pycore_modsupport.h includes when a C extension uses one of these functions. * Define Py_BUILD_CORE_MODULE in C extensions which now include directly or indirectly (via code generated by Argument Clinic) pycore_modsupport.h: * _csv * _curses_panel * _dbm * _gdbm * _multiprocessing.posixshmem * _sqlite.row * _statistics * grp * resource * syslog * _testcapi: bad_get() no longer uses METH_FASTCALL calling convention but METH_VARARGS. Replace _PyArg_UnpackStack() with PyArg_ParseTuple(). * _testcapi: add PYTESTCAPI_NEED_INTERNAL_API macro which is defined by _testcapi sub-modules which need the internal C API (pycore_modsupport.h): exceptions.c, float.c, vectorcall.c, watchers.c. * Remove Include/cpython/modsupport.h header file. Include/modsupport.h no longer includes the removed header file. * Fix mypy clinic.py
* gh-109595: Add -Xcpu_count=<n> cmdline for container users (#109667)Donghee Na2023-10-101-1/+29
| | | | | | --------- Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
* gh-108753: Enhance pystats (#108754)Victor Stinner2023-09-061-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Statistics gathering is now off by default. Use the "-X pystats" command line option or set the new PYTHONSTATS environment variable to 1 to turn statistics gathering on at Python startup. Statistics are no longer dumped at exit if statistics gathering was off or statistics have been cleared. Changes: * Add PYTHONSTATS environment variable. * sys._stats_dump() now returns False if statistics are not dumped because they are all equal to zero. * Add PyConfig._pystats member. * Add tests on sys functions and on setting PyConfig._pystats to 1. * Add Include/cpython/pystats.h and Include/internal/pycore_pystats.h header files. * Rename '_py_stats' variable to '_Py_stats'. * Exclude Include/cpython/pystats.h from the Py_LIMITED_API. * Move pystats.h include from object.h to Python.h. * Add _Py_StatsOn() and _Py_StatsOff() functions. Remove '_py_stats_struct' variable from the API: make it static in specialize.c. * Document API in Include/pystats.h and Include/cpython/pystats.h. * Complete pystats documentation in Doc/using/configure.rst. * Don't write "all zeros" stats: if _stats_off() and _stats_clear() or _stats_dump() were called. * _PyEval_Fini() now always call _Py_PrintSpecializationStats() which does nothing if stats are all zeros. Co-authored-by: Michael Droettboom <mdboom@gmail.com>
* gh-107603: Argument Clinic: Only include pycore_gc.h if needed (#108726)Victor Stinner2023-08-319-46/+22
| | | | | | | | | | | | | | | | | | | | Argument Clinic now only includes pycore_gc.h if PyGC_Head is needed, and only includes pycore_runtime.h if _Py_ID() is needed. * Add 'condition' optional argument to Clinic.add_include(). * deprecate_keyword_use() includes pycore_runtime.h when using the _PyID() function. * Fix rendering of includes: comments start at the column 35. * Mark PC/clinic/_wmimodule.cpp.h and "Objects/stringlib/clinic/*.h.h" header files as generated in .gitattributes. Effects: * 42 header files generated by AC no longer include the internal C API, instead of 4 header files before. For example, Modules/clinic/_abc.c.h no longer includes the internal C API. * Fix _testclinic_depr.c.h: it now always includes pycore_runtime.h to get _Py_ID().
* gh-106320: Remove private AC converter functions (#108505)Victor Stinner2023-08-261-1/+2
| | | | | | | | | | | | | | Move these private functions to the internal C API (pycore_abstract.h): * _Py_convert_optional_to_ssize_t() * _PyNumber_Index() Argument Clinic now emits #include "pycore_abstract.h" when these functions are used. The parser of the c-analyzer tool now uses a list of files which use the limited C API, rather than a list of files using the internal C API.
* gh-108444: Argument Clinic uses PyLong_AsInt() (#108458)Victor Stinner2023-08-247-37/+37
| | | | Argument Clinic now uses the new public PyLong_AsInt(), rather than the old name _PyLong_AsInt().
* gh-107526: Revert "gh-100357: Convert several functions in bltinsmodule to ↵Nikita Sobolev2023-08-211-195/+1
| | | | AC" (#107542)
* gh-92536: Argument Clinic no longer emits PyUnicode_READY() (#105208)Victor Stinner2023-06-014-34/+4
| | | | | | Since Python 3.12, PyUnicode_READY() does nothing and always returns 0. Argument Clinic now also checks for .cpp files (PC/_wmimodule.cpp).
* gh-105069: Add a readline-like callable to the tokenizer to consume input ↵Pablo Galindo Salgado2023-05-301-17/+24
| | | | iteratively (#105070)
* gh-102856: Python tokenizer implementation for PEP 701 (#104323)Marta Gómez Macías2023-05-211-8/+14
| | | | | | | | | | | This commit replaces the Python implementation of the tokenize module with an implementation that reuses the real C tokenizer via a private extension module. The tokenize module now implements a compatibility layer that transforms tokens from the C tokenizer into Python tokenize tokens for backward compatibility. As the C tokenizer does not emit some tokens that the Python tokenizer provides (such as comments and non-semantic newlines), a new special mode has been added to the C tokenizer mode that currently is only used via the extension module that exposes it to the Python layer. This new mode forces the C tokenizer to emit these new extra tokens and add the appropriate metadata that is needed to match the old Python implementation. Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-84436: Implement Immortal Objects (gh-19474)Eddie Elizondo2023-04-221-1/+29
| | | | | | | | | This is the implementation of PEP683 Motivation: The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime. Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
* GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython ↵Mark Shannon2023-04-121-0/+311
| | | | | | | | | | (GH-103083) * The majority of the monitoring code is in instrumentation.c * The new instrumentation bytecodes are in bytecodes.c * legacy_tracing.c adapts the new API to the old sys.setrace and sys.setprofile APIs
* gh-98627: Add an Optional Check for Extension Module Subinterpreter ↵Eric Snow2023-02-161-1/+32
| | | | | | | | | | | | | | | Compatibility (gh-99040) Enforcing (optionally) the restriction set by PEP 489 makes sense. Furthermore, this sets the stage for a potential restriction related to a per-interpreter GIL. This change includes the following: * add tests for extension module subinterpreter compatibility * add _PyInterpreterConfig.check_multi_interp_extensions * add Py_RTFLAGS_MULTI_INTERP_EXTENSIONS * add _PyImport_CheckSubinterpIncompatibleExtensionAllowed() * fail iff the module does not implement multi-phase init and the current interpreter is configured to check https://github.com/python/cpython/issues/98627