[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Okay. As a workaround we can explicitly specify the dispatching type: @f.register(list) def _(a: list[int]) -> None: pass -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python

[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Alex Waygood
Alex Waygood added the comment: Yeah, I think I agree with Guido. Mypy only has partial support for singledispatch anyway, and only achieves that through a plugin, so special-casing by type-checkers is inevitable. -- ___ Python tracker

[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Guido van Rossum
Guido van Rossum added the comment: If we allow registering list[int] but give it the same meaning as registering plain list (at runtime), that would violate user expectations pretty strongly -- for the same reason why we don't allow isinstance(x, list[int]). If you want stronger checking

[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Alex Waygood
Alex Waygood 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

[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I do not think there is a problem in MyPy. What if use __origin__ for dispatching? Registering with parametrized generics with the same __origin__ will be error. @sigledispatch def f(a: int) -> None: pass @f.register # ok def _(a: list[int]) ->

[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Guido van Rossum
Guido van Rossum added the comment: That mypy error is only reported with a certain mypy setting (--strict, or probably one of the specific settings that that turns on). We won't be supporting Sequence[Any] at runtime (because we only support actual types), but we should support Sequence,

[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Alex Waygood
Change by Alex Waygood : -- nosy: +AlexWaygood, lukasz.langa ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46191] Conflict between using annotations in singledispatch() and MyPy

2021-12-29 Thread Serhiy Storchaka
New submission from Serhiy Storchaka : You can dispatch on collections.abc.Sequence. @functools.singledispatch def f(a: collections.abc.Sequence) -> None: pass But MyPy complains about this: error: Missing type parameters for generic type "Sequence" MyPy requires parametrized generic