summaryrefslogtreecommitdiffstats
path: root/Objects/unionobject.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-119180: Add evaluate functions for type params and type aliases (#122212)Jelle Zijlstra2024-07-271-64/+2
|
* Fixes loop variables to be the same types as their limit (GH-120958)Steve Dower2024-06-241-2/+2
|
* gh-119182: Use public PyUnicodeWriter API in union_repr() (#120797)Victor Stinner2024-06-201-24/+30
| | | | | | | | | | | | | | | The public PyUnicodeWriter API enables overallocation by default and so is more efficient. Benchmark: python -m pyperf timeit \ -s 't = int | float | complex | str | bytes | bytearray' \ ' | memoryview | list | dict' \ 'str(t)' Result: 1.29 us +- 0.02 us -> 1.00 us +- 0.02 us: 1.29x faster
* gh-108511: Add C API functions which do not silently ignore errors (GH-109025)Serhiy Storchaka2023-09-171-17/+10
| | | | | | | | | Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
* Add missing `PyDoc_STR` calls (#109393)Nikita Sobolev2023-09-151-1/+2
| | | | | | | | | In files: * Modules/_ctypes/cfield.c * Modules/_struct.c * Objects/dictobject.c * Objects/typevarobject.c * Objects/unionobject.c
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-4/+4
|
* gh-104549: Set __module__ on TypeAliasType (#104550)Jelle Zijlstra2023-05-181-3/+4
|
* gh-103763: Implement PEP 695 (#103764)Jelle Zijlstra2023-05-161-2/+6
| | | | | | | | | | | | | | This implements PEP 695, Type Parameter Syntax. It adds support for: - Generic functions (def func[T](): ...) - Generic classes (class X[T](): ...) - Type aliases (type X = ...) - New scoping when the new syntax is used within a class body - Compiler and interpreter changes to support the new syntax and scoping rules Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Eric Traut <eric@traut.com> Co-authored-by: Larry Hastings <larry@hastings.org> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-99300: Replace Py_INCREF() with Py_NewRef() (#99530)Victor Stinner2022-11-161-2/+1
| | | | Replace Py_INCREF() and Py_XINCREF() using a cast with Py_NewRef() and Py_XNewRef().
* gh-99300: Use Py_NewRef() in Objects/ directory (#99354)Victor Stinner2022-11-101-10/+5
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
* gh-91603: Speed up isinstance/issubclass on union types (GH-91631)Yurii Karabas2022-04-281-74/+7
| | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-91603: Speed up operator "|" for UnionType (GH-91955)Serhiy Storchaka2022-04-281-87/+70
| | | | | | | | | Reduce the complexity from O((M+N)^2) to O(M*N), where M and N are the length of __args__ for both operands (1 for operand which is not a UnionType). As a consequence, the complexity of parameter substitution in UnionType has been reduced from O(N^3) to O(N^2). Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* gh-91118: Fix docstrings that do not honor --without-doc-strings (#31769)Oleg Iarygin2022-04-181-2/+2
| | | | Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-8/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-44662: Add ability to annotate types.Union (#27214)Yurii Karabas2021-07-291-1/+23
| | | Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-44732: Rename types.Union to types.UnionType (#27342)Hasan2021-07-261-3/+3
| | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-44676: Serialize the union type using only public API (GH-27323)Serhiy Storchaka2021-07-241-48/+0
| | | | Remove also the _from_args() constructor.
* bpo-44676: Fix reference leaks in union_reduce (GH-27332)Pablo Galindo Salgado2021-07-241-1/+1
| | | Automerge-Triggered-By: GH:pablogsal
* bpo-44731: Simplify the union type implementation (GH-27318)Serhiy Storchaka2021-07-241-81/+7
| | | Remove direct support of typing types in the C code because they are already supported by defining methods __or__ and __ror__ in the Python code.
* bpo-44676: Add ability to serialize types.Union (GH-27244)Yurii Karabas2021-07-231-0/+51
|
* bpo-44653: Support typing types in parameter substitution in the union type. ↵Serhiy Storchaka2021-07-221-13/+12
| | | | (GH-27247)
* bpo-44633: Fix parameter substitution of the union type with wrong types. ↵Serhiy Storchaka2021-07-181-16/+28
| | | | | | (GH-27218) A TypeError is now raised instead of returning NotImplemented.
* bpo-44654: Refactor and clean up the union type implementation (GH-27196)Serhiy Storchaka2021-07-171-88/+47
|
* bpo-44652: Preserve natural order of args in the union type. (GH-27185)Serhiy Storchaka2021-07-161-2/+2
|
* bpo-44636: Collapse union of equal types (GH-27178)Serhiy Storchaka2021-07-161-8/+16
| | | | | | The result of `int | int` is now `int`. Fix comparison of the union type with non-hashable objects. `int | str == {}` no longer raises a TypeError.
* bpo-44646: Fix the hash of the union type. (#27179)Serhiy Storchaka2021-07-161-4/+6
| | | | | | It no longer depends on the order of arguments. hash(int | str) == hash(str | int) Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
* bpo-44632: Fix support of TypeVar in the union type (GH-27139)Serhiy Storchaka2021-07-141-1/+1
| | | | int | TypeVar('T') returns now an instance of types.Union instead of typing.Union.
* bpo-44635: Convert None to NoneType in the union type constructor (GH-27136)Serhiy Storchaka2021-07-141-9/+7
|
* bpo-44606: Fix __instancecheck__ and __subclasscheck__ for the union type. ↵Serhiy Storchaka2021-07-141-4/+19
| | | | | | | | | | (GH-27120) * Fix issubclass() for None. E.g. issubclass(type(None), int | None) returns now True. * Fix issubclass() for virtual subclasses. E.g. issubclass(dict, int | collections.abc.Mapping) returns now True. * Fix crash in isinstance() if the check for one of items raises exception.
* bpo-44490: Add __parameters__ and __getitem__ to types.Union (GH-26980)Yurii Karabas2021-07-061-0/+53
| | | | Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
* bpo-44553: Correct failure in tp_new for the union object (GH-27008)Pablo Galindo2021-07-031-2/+2
|
* bpo-44553 : Implement GC methods for types.Union (GH-26993)Ken Jin2021-07-031-4/+17
|
* bpo-44483: Fix crash in union object with bad ``__module__`` (GH-26848)Ken Jin2021-06-221-3/+14
|
* bpo-42195: Disallow isinstance/issubclass for subclasses of genericaliases ↵Ken Jin2021-01-021-1/+1
| | | | | | | | | | | | | | in Union (GH-24059) Previously this didn't raise an error. Now it will: ```python from collections.abc import Callable isinstance(int, list | Callable[..., str]) ``` Also added tests in Union since there were previously none for stuff like ``isinstance(list, list | list[int])`` either. Backport to 3.9 not required. Automerge-Triggered-By: GH:gvanrossum
* bpo-42195: Ensure consistency of Callable's __args__ in collections.abc and ↵kj2020-12-131-3/+3
| | | | typing (GH-23060)
* bpo-42233: Add union type expression support for GenericAlias and fix ↵kj2020-11-091-5/+15
| | | | de-duplicating of GenericAlias (GH-23077)
* bpo-42099: Fix reference to ob_type in unionobject.c and ceval (GH-22829)Neil Schemenauer2020-10-271-1/+1
| | | * Use Py_TYPE() rather than o->ob_type.
* bpo-41991: Remove _PyObject_HasAttrId (GH-22629)Serhiy Storchaka2020-10-101-6/+7
| | | It can silence arbitrary exceptions.
* bpo-41428: Fix compiler warning in unionobject.c (GH-22416)Victor Stinner2020-09-261-3/+3
| | | | | | | Use Py_ssize_t type rather than int, to store lengths in unionobject.c. Fix the warning: Objects\unionobject.c(205,1): warning C4244: 'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data
* bpo-41428: Fix compiler warnings in unionobject.c (GH-22388)Victor Stinner2020-09-231-3/+3
| | | | | | | | | | | | | | | | Use Py_ssize_t type rather than int, to store lengths in unionobject.c. Fix warnings: Objects\unionobject.c(189,71): warning C4244: '+=': conversion from 'Py_ssize_t' to 'int', possible loss of data Objects\unionobject.c(182,1): warning C4244: 'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data Objects\unionobject.c(205,1): warning C4244: 'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data Objects\unionobject.c(437,1): warning C4244: 'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data
* bpo-41428: Implementation for PEP 604 (GH-21515)Maggie Moss2020-09-091-0/+464
See https://www.python.org/dev/peps/pep-0604/ for more information. Co-authored-by: Pablo Galindo <pablogsal@gmail.com>