Alex Waygood <alex.wayg...@gmail.com> added the comment:
I like Serhiy's idea from a type-checking perspective. It would mean we could continue to have sophisticated type inference from mypy/pyright/etc. inside singledispatch function definitions. It would also mean people could use type annotations in singledispatch functions in much the same way as in the rest of their code, instead of having to remember that *this specific stdlib function* works differently. Lastly, it avoids having to have each type-checker separately special-case singledispatch so that they do not raise an error when an unparameterised generic is used as a type annotation. My concern, however, is that the runtime semantics are slightly unintuitive. Registering an implementation to the "type" `list[str]` (and having it succeed without an error being raised) might give the false implication that there will be runtime checking of whether all the elements in a list are strings. I also think that GenericAlias objects should probably only be accepted in the form of `singledispatch.register()` that parses type annotations. There's no use case for allowing GenericAlias objects in the other forms of registering implementations. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46191> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com