[issue46032] functools' singledispatch does not support GenericAlias

Alex Waygood report at bugs.python.org
Fri Dec 10 04:21:40 EST 2021


Alex Waygood <Alex.Waygood at Gmail.com> added the comment:

My opinion is that supporting `GenericAlias` here would be a bad idea. Associating an implementation of the function with the argument type `list[str]` is ambiguous. Would this implementation be called if any argument of type `list` was supplied, or would it only be called if all elements in the list were of type `str`?

The first option would be efficient, simple, and similar to the way singledispatch treats most other argument-types. However, it would be unintuitive.

The second option would be more intuitive, but could be extremely inefficient if a very long list was passed in. It would also make the code more complicated.

----------
nosy: +AlexWaygood, lukasz.langa

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


More information about the Python-bugs-list mailing list