summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)Victor Stinner2022-11-231-6/+3
| | | Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
* gh-99300: Use Py_NewRef() in Objects/ directory (#99332)Victor Stinner2022-11-101-15/+7
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
* gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)Serhiy Storchaka2022-06-141-8/+1
| | | | | | It combines PyImport_ImportModule() and PyObject_GetAttrString() and saves 4-6 lines of code on every use. Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
* Use static inline function Py_EnterRecursiveCall() (#91988)Victor Stinner2022-05-041-11/+11
| | | | | | | | | | | | | | | | Currently, calling Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() may use a function call or a static inline function call, depending if the internal pycore_ceval.h header file is included or not. Use a different name for the static inline function to ensure that the static inline function is always used in Python internals for best performance. Similar approach than PyThreadState_GET() (function call) and _PyThreadState_GET() (static inline function). * Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate() * Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate() * pycore_ceval.h: Rename Py_EnterRecursiveCall() to _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and _Py_LeaveRecursiveCall()
* gh-92114: Improve error message for types with __class_getitem__ = None ↵Serhiy Storchaka2022-05-021-1/+2
| | | | (GH-92115)
* gh-91603: Speed up isinstance/issubclass on union types (GH-91631)Yurii Karabas2022-04-281-0/+8
| | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* bpo-46927: Include the type's name in the error message for subscripting ↵Serhiy Storchaka2022-03-051-0/+3
| | | | non-generic types (GH-31694)
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-32/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-44977: Deprecate delegation of int to __trunc__ (GH-31031)Zackery Spytz2022-02-031-0/+5
| | | | | Calling int(a) when type(a) implements __trunc__ but not __int__ or __index__ now raises a DeprecationWarning.
* bpo-46140: take more Py_buffer arguments as const * (GH-30217)David Hewitt2021-12-221-3/+4
|
* bpo-45760: Remove PyNumber_InMatrixMultiply (GH-29751)Dong-hee Na2021-11-261-29/+4
|
* bpo-45636: Simplify BINARY_OP (GH-29565)Brandt Bucher2021-11-161-0/+12
|
* bpo-30570: Use Py_EnterRecursiveCall() in issubclass() (GH-29048)Dennis Sweeney2021-10-221-6/+14
| | | | | * Use Py_EnterRecursiveCall() in issubclass() Reviewed-by: Gregory P. Smith <greg@krypto.org> [Google]
* bpo-35134: Move classobject.h to Include/cpython/ (GH-28968)Victor Stinner2021-10-151-1/+0
| | | | | | | | | Move classobject.h, context.h, genobject.h and longintrepr.h header files from Include/ to Include/cpython/. Remove redundant "#ifndef Py_LIMITED_API" in context.h. Remove explicit #include "longintrepr.h" in C files. It's not needed, Python.h already includes it.
* bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)Victor Stinner2021-10-121-0/+1
| | | | | | | * Move _PyObject_CallNoArgs() to pycore_call.h (internal C API). * _ssl, _sqlite and _testcapi extensions now call the public PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs(). * _lsprof extension is now built with Py_BUILD_CORE_MODULE macro defined to get access to internal _PyObject_CallNoArgs().
* bpo-45439: Rename _PyObject_CallNoArg() to _PyObject_CallNoArgs() (GH-28891)Victor Stinner2021-10-111-2/+2
| | | | | Fix typo in the private _PyObject_CallNoArg() function name: rename it to _PyObject_CallNoArgs() to be consistent with the public function PyObject_CallNoArgs().
* bpo-44640: Improve punctuation consistency in isinstance/issubclass error ↵wyz23x22021-09-171-2/+2
| | | | | messages (GH-27144) Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-45123: PyAiter_Check and PyObject_GetAiter fix & rename. (GH-28194)Yury Selivanov2021-09-071-7/+5
| | | | | | | | Fix PyAiter_Check to only check for the `__anext__` presense (not for `__aiter__`). Rename `PyAiter_Check()` to `PyAIter_Check()`, `PyObject_GetAiter()` -> `PyObject_GetAIter()`. Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* bpo-41103: Resurrect the old buffer protocol. (GH-27437)Inada Naoki2021-07-291-0/+79
| | | | | Revert "bpo-41103: Remove old buffer protocol support (#21117)" This reverts commit 6f8a6ee59cb7f99f68df8ee9c3e8c8cf19af3eed.
* bpo-42747: Remove Py_TPFLAGS_HAVE_AM_SEND and make ↵Petr Viktorin2021-07-231-3/+1
| | | | | | | | | | | | Py_TPFLAGS_HAVE_VERSION_TAG no-op (GH-27260) * Remove code that checks Py_TPFLAGS_HAVE_VERSION_TAG The field is always present in the type struct, as explained in the added comment. * Remove Py_TPFLAGS_HAVE_AM_SEND The flag is not needed, and since it was added in 3.10 it can be removed now.
* bpo-44654: Refactor and clean up the union type implementation (GH-27196)Serhiy Storchaka2021-07-171-4/+2
|
* bpo-31861: Add aiter and anext to builtins (#23847)Joshua Bronson2021-03-231-0/+31
| | | | | | Co-authored-by: jab <jab@users.noreply.github.com> Co-authored-by: Daniel Pope <mauve@mauveweb.co.uk> Co-authored-by: Justin Wang <justin39@gmail.com>
* bpo-38302: __pow__/__rpow__ now called when __ipow__ returns NotImplemented ↵Alex2021-02-261-21/+27
| | | | (#16459)
* bpo-40170: Always define PyIter_Check() as a function (GH-24548)Erlend Egeberg Aasland2021-02-161-5/+5
|
* bpo-42979: Use _Py_CheckSlotResult() to check slots result (GH-24356)Victor Stinner2021-01-291-187/+282
| | | | | | | | | | | | | | | When Python is built in debug mode (with C assertions), calling a type slot like sq_length (__len__() in Python) now fails with a fatal error if the slot succeeded with an exception set, or failed with no exception set. The error message contains the slot, the type name, and the current exception (if an exception is set). * Check the result of all slots using _Py_CheckSlotResult(). * No longer pass op_name to ternary_op() in release mode. * Replace operator with dunder Python method name in error messages. For example, replace "*" with "__mul__". * Fix compiler_exit_scope() when an exception is set. * Fix bytearray.extend() when an exception is set: don't call bytearray_setslice() with an exception set.
* bpo-42979: Enhance abstract.c assertions checking slot result (GH-24352)Victor Stinner2021-01-271-8/+9
| | | | | | | | * bpo-42979: Enhance abstract.c assertions checking slot result Add _Py_CheckSlotResult() function which fails with a fatal error if a slot function succeeded with an exception set or failed with no exception set: write the slot name, the type name and the current exception (if an exception is set).
* bpo-42085: Introduce dedicated entry in PyAsyncMethods for sending values ↵Vladimir Matveev2020-11-101-0/+26
| | | | (#22780)
* Delete PyGen_Send (#22663)Vladimir Matveev2020-10-121-25/+0
|
* bpo-41756: Add PyIter_Send function (#22443)Vladimir Matveev2020-10-101-0/+24
|
* bpo-41974: Remove complex.__float__, complex.__floordiv__, etc (GH-22593)Serhiy Storchaka2020-10-091-5/+5
| | | | | | Remove complex special methods __int__, __float__, __floordiv__, __mod__, __divmod__, __rfloordiv__, __rmod__ and __rdivmod__ which always raised a TypeError.
* bpo-41909: Enable previously disabled recursion checks. (GH-22536)Serhiy Storchaka2020-10-041-2/+0
| | | | | | | | | | | Enable recursion checks which were disabled when get __bases__ of non-type objects in issubclass() and isinstance() and when intern strings. It fixes a stack overflow when getting __bases__ leads to infinite recursion. Originally recursion checks was disabled for PyDict_GetItem() which silences all errors including the one raised in case of detected recursion and can return incorrect result. But now the code uses PyDict_GetItemWithError() and PyDict_SetDefault() instead.
* bpo-41428: Implementation for PEP 604 (GH-21515)Maggie Moss2020-09-091-6/+9
| | | | | See https://www.python.org/dev/peps/pep-0604/ for more information. Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-39573: Use the Py_TYPE() macro (GH-21433)Victor Stinner2020-07-101-2/+2
| | | Replace obj->ob_type with Py_TYPE(obj).
* bpo-41123: Remove PyLong_FromUnicode() (GH-21204)Inada Naoki2020-06-291-1/+1
|
* bpo-41103: Remove old buffer protocol support (#21117)Inada Naoki2020-06-251-79/+0
| | | They are deprecated since Python 3.0.
* bpo-36710: Pass tstate explicitly in abstract.c (GH-21075)Victor Stinner2020-06-231-40/+61
| | | | In functions calling more than one PyErr function, get tstate and then pass it explicitly.
* bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. ↵Serhiy Storchaka2020-06-221-1/+3
| | | | | | | (GH-20537) Unexpected errors in calling the __iter__ method are no longer masked by TypeError in the "in" operator and functions operator.contains(), operator.indexOf() and operator.countOf().
* bpo-40792: Make the result of PyNumber_Index() always having exact type int. ↵Serhiy Storchaka2020-05-281-12/+20
| | | | | | | | | | | | (GH-20443) Previously, the result could have been an instance of a subclass of int. Also revert bpo-26202 and make attributes start, stop and step of the range object having exact type int. Add private function _PyNumber_Index() which preserves the old behavior of PyNumber_Index() for performance to use it in the conversion functions like PyLong_AsLong().
* bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)Serhiy Storchaka2020-05-261-7/+24
| | | | Only __index__ should be used to make integer conversions lossless.
* bpo-38787: Add PyCFunction_CheckExact() macro for exact type checks (GH-20024)scoder2020-05-121-1/+1
| | | | | … now that we allow subtypes of PyCFunction. Also add PyCMethod_CheckExact() and PyCMethod_Check() for checks against the PyCMethod subtype.
* bpo-39465: Don't access directly _Py_Identifier members (GH-20043)Victor Stinner2020-05-111-1/+1
| | | | | * Replace id->object with _PyUnicode_FromId(&id) * Use _Py_static_string_init(str) macro to initialize statically name_op in typeobject.c.
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-4/+4
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner2020-04-141-1/+1
|
* bpo-40170: Remove PyIndex_Check() macro (GH-19428)Victor Stinner2020-04-081-2/+0
| | | | | Always declare PyIndex_Check() as an opaque function to hide implementation details: remove PyIndex_Check() macro. The macro accessed directly the PyTypeObject.tp_as_number member.
* bpo-40170: Add _PyIndex_Check() internal function (GH-19426)Victor Stinner2020-04-081-9/+11
| | | | | | | | | Add _PyIndex_Check() function to the internal C API: fast inlined verson of PyIndex_Check(). Add Include/internal/pycore_abstract.h header file. Replace PyIndex_Check() with _PyIndex_Check() in C files of Objects and Python subdirectories.
* bpo-40170: Convert PyObject_CheckBuffer() macro to a function (GH-19376)Victor Stinner2020-04-071-0/+10
| | | | | Convert PyObject_CheckBuffer() macro to a function to hide implementation details: the macro accessed directly the PyTypeObject.tp_as_buffer member.
* bpo-39481: Implementation for PEP 585 (#18239)Guido van Rossum2020-04-071-0/+6
| | | | | | | | | | | | This implements things like `list[int]`, which returns an object of type `types.GenericAlias`. This object mostly acts as a proxy for `list`, but has attributes `__origin__` and `__args__` that allow recovering the parts (with values `list` and `(int,)`. There is also an approximate notion of type variables; e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`. Type variables are objects of type `typing.TypeVar`.
* bpo-39947: Move Py_EnterRecursiveCall() to internal C API (GH-18972)Victor Stinner2020-03-131-0/+1
| | | | | | Move the static inline function flavor of Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() to the internal C API: they access PyThreadState attributes. The limited C API provides regular functions which hide implementation details.
* bpo-38643: Raise SystemError instead of crashing when PyNumber_ToBase is ↵Serhiy Storchaka2020-03-091-9/+6
| | | | called with invalid base. (GH-18863)
* bpo-39573: Use Py_IS_TYPE() macro to check for types (GH-18809)Andy Lester2020-03-061-3/+2
| | | Co-authored-by: Victor Stinner <vstinner@python.org>