[issue44578] dict/list with more than two type parameters doesn't raise a TypeError
Ken Jin
report at bugs.python.org
Wed Jul 7 10:24:45 EDT 2021
Ken Jin <kenjin4096 at gmail.com> added the comment:
Sorry, I don't think this will be fixed as it is intentional. types.GenericAlias (the type of list[int] or dict[str, str]) does almost 0 checking for two reasons IIUC:
- Types with wrong number of parameters will usually be caught by your IDE/type checker.
- Checking would add complexity and slow down runtime performance. The current implementation of GenericAlias in C is intentionally simple.
We can add a note in the docs noting that too many type parameters won't raise a TypeError. It would probably be here https://docs.python.org/3/library/stdtypes.html#generic-alias-type
BTW, I adjusted the issue's affected versions because this was introduced only in 3.9.
----------
nosy: +gvanrossum, kj
versions: +Python 3.10, Python 3.11 -Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44578>
_______________________________________
More information about the Python-bugs-list
mailing list