This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mthe
Recipients mthe
Date 2021-07-07.11:37:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1625657874.87.0.018743781602.issue44578@roundup.psfhosted.org>
In-reply-to
Content
dict with three type parameters is legal (e.g., dict[str, str, str]), where I expected a TypeError. When using typing.Dict, it does raise a TypeError.

Example in python 3.9:

>>> from typing import Dict
>>> Dict[str, str, str]  # Raises a TypeError, as expected
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/michaelthe/.pyenv/versions/3.9.6/lib/python3.9/typing.py", line 275, in inner
    return func(*args, **kwds)
  File "/Users/michaelthe/.pyenv/versions/3.9.6/lib/python3.9/typing.py", line 828, in __getitem__
    _check_generic(self, params, self._nparams)
  File "/Users/michaelthe/.pyenv/versions/3.9.6/lib/python3.9/typing.py", line 212, in _check_generic
    raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for {cls};"
TypeError: Too many parameters for typing.Dict; actual 3, expected 2
>>> dict[str, str, str]  # No TypeError here?
dict[str, str, str]

This also works in 3.7 and 3.8:

Python 3.8.11 (default, Jul  6 2021, 12:13:09) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>> dict[str, str, str]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
>>> def foo(bar: dict[str, str, str]): pass
... 
>>> foo.__annotations__
{'bar': 'dict[str, str, str]'}
History
Date User Action Args
2021-07-07 11:37:54mthesetrecipients: + mthe
2021-07-07 11:37:54mthesetmessageid: <1625657874.87.0.018743781602.issue44578@roundup.psfhosted.org>
2021-07-07 11:37:54mthelinkissue44578 messages
2021-07-07 11:37:54mthecreate