[issue44654] Refactor and clean up the union type implementation

Ken Jin report at bugs.python.org
Fri Jul 16 11:42:07 EDT 2021


Ken Jin <kenjin4096 at gmail.com> added the comment:

> I am going to backport these changes to 3.10 to make backporting of future fixes easier.
> * Move declarations of _Py_make_parameters and _Py_subs_parameters ...

Unfortunately, _Py_make_parameters and _Py_subs_parameters are 3.11 only. They were part of https://github.com/python/cpython/pull/26980. And we couldn't backport it to 3.10 (please see the PR thread). Maybe we can ask Pablo to reconsider for addition in 3.10rc1 if we can get a core dev to approve that?

> * Perform cheaper tests before more expensive tests in is_unionable().
> * Optimize __module__ look up in is_typing_module().

Yeah I noticed it re-lookups __module__ unnecessarily multiple times for the same type. I tried fixing this a month ago (and also convert to interned PyId strings) but for some reason microbenchmarks didn't show much gain. Things may be different after you clean things up.

> * Extract related tests to separate class.

Yes please :). Maybe even a separate file altogether. GenericAlias has its own test_genericalias.

A big +1 on everything else. They were bugging me for a while but I didn't have the time to fix them. Thanks for taking this up Serhiy :)!

----------

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


More information about the Python-bugs-list mailing list