[New-bugs-announce] [issue44654] Refactor and clean up the union type implementation

Serhiy Storchaka report at bugs.python.org
Fri Jul 16 11:24:47 EDT 2021


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

I started reviewing and rewriting Objects/unionobject.c several weeks ago. Some discovered bugs were reported and fixed in separate issues: issue44606, issue44632, issue44635, issue44636, issue44646, issue44652. Before fixing the remaining bugs (issue44633, issue44642, issue44653) I want to merge some minor changes:

* Rename _Py_UnionType to _PyUnion_Type. It is how PyTypeObject instances are named.
* Add _PyUnion_Check() and _PyGenericAlias_Check(). It simplified the code.
* Do not expose _Py_Union(). It is only used locally.
* Move declarations of _Py_make_parameters and _Py_subs_parameters from genericaliasobject.h to internal/pycore_unionobject.h. They are for internal use only.
* Fix a possible leak in dedup_and_flatten_args().
* Significantly simplify union_richcompare(). The Python implementation can be used for comparing types.Union with typing.Union.
* Perform cheaper tests before more expensive tests in is_unionable().
* Optimize __module__ look up in is_typing_module() and support types without __module__.
* Fix outdated comments.
* Minor style fixes.
* Extract related tests to separate class.
* Make some tests more accurate: they should test for TypeError only specific operators, not constructors.

I am going to backport these changes to 3.10 to make backporting of future fixes easier.

----------
components: Interpreter Core
messages: 397635
nosy: gvanrossum, kj, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Refactor and clean up the union type implementation
versions: Python 3.10, Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44654>
_______________________________________


More information about the New-bugs-announce mailing list