Message 408306 - Python tracker (original) (raw)
Yes, it is related to . It is a complicated case due to coincidence of several circumstances.
isinstance(list[int], type) is True, while isinstance(typing.List[int], type) is False. list[int] is considered a type in this check.
list[int].mro == list.mro, while typing.List[int] does not have the mro attribute. list[int] is considered a type in this check.
issubclass(cls, list[int]) raises a TypeError (the same for typing.List[int]). list[int] cannot be used as a type here.
2-argument registry() does not check the type of its first argument. f.registry(42, ...) is silently passed.
In 2-argument registry() typing.List[int] is passed due to (4) and ignored in dispatch() due to (2). list[int] is passed due to (4), but caused error due to (3).
In other uses of registry() (1-argument decorator factory and decorator with annotations) typing.List[int] is not passed due to 1. list[int] is passed due to (1) and caused error due to (3).
The proposed PR makes list[int] be treated the same way as typing.List[int]. It also makes 2-argument registry() rejecting invalid first argument, so all three forms of registry() accept and reject now the same types.