[issue47030] singledispatch does not work with positional arguments with default values.

Andrei Kulakov report at bugs.python.org
Mon Mar 21 23:50:00 EDT 2022


Andrei Kulakov <andrei.avk at gmail.com> added the comment:

This would be problematic for two reasons:

 - possible confusion between the default function that runs when an argument doesn't match any registered types, and another "default" which runs when argument is omitted.

 - to see which function will run when argument is omitted, you would need to check in two places - the default value of arg and then find the registered function that matches it. If we end up deciding there is a need to run a default handler when an argument is omitted, it would be more explicit and convenient and visually obvious to decorate the "default if no arg" handler in some way, which also means there'd be a single place where this behavior is defined.

We can also consider adding a note to documentation that the first argument used for dispatch should not have a default value, to make it more explicit that dispatching on default value is not supported.

----------
nosy: +andrei.avk

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


More information about the Python-bugs-list mailing list