Alex Waygood <alex.wayg...@gmail.com> added the comment:

To clarify why this is an issue:

It's probably quite improbable that anybody would ever need to use 
`singledispatchmethod` in a type annotation. But, if they do, they'll find 
themselves in an impossible situation if they're using mypy with the `--strict` 
setting. If you're using `--strict` (as I always do), mypy will complain if you 
leave unparameterised any class that is marked as a generic in typeshed. But if 
you try to parameterise `singledispatchmethod`, and you're not using `from 
__future__ import annotations`, your code will fail at runtime.

It would be better if the cpython source were changed to add 
`__class_getitem__` to `singledispatchmethod`, rather than making the class no 
longer generic in typeshed. This is because being able to parameterise classes 
gives mypy much more information to work with, giving it the ability to provide 
far more fine-grained analysis of your code.

Here is a minimal reproducible example of the error mypy will give: 
https://mypy-play.net/?mypy=latest&python=3.10&flags=show-error-codes%2Cstrict

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45684>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to