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 stefanistrate
Recipients stefanistrate
Date 2021-09-06.16:11:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630944704.92.0.838059763947.issue45117@roundup.psfhosted.org>
In-reply-to
Content
According to PEP 585 (https://www.python.org/dev/peps/pep-0585/#implementation), I expect that typing aliases could simply use `dict` instead of `typing.Dict`. This works without problems in Python 3.9, but in Python 3.8, despite using `from __future__ import annotations`, I get the following error:



$ /usr/local/Cellar/python@3.8/3.8.11/bin/python3.8
Python 3.8.11 (default, Jun 29 2021, 03:08:07)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>> from typing import Any
>>> JsonDictType = dict[str, Any]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable



However, `dict` is subscriptable when not used in an alias:



$ /usr/local/Cellar/python@3.8/3.8.11/bin/python3.8
Python 3.8.11 (default, Jun 29 2021, 03:08:07)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>> from typing import Any
>>> def f(d: dict[str, Any]):
...     print(d)
...
>>> f({"abc": 1, "def": 2})
{'abc': 1, 'def': 2}
History
Date User Action Args
2021-09-06 16:11:44stefanistratesetrecipients: + stefanistrate
2021-09-06 16:11:44stefanistratesetmessageid: <1630944704.92.0.838059763947.issue45117@roundup.psfhosted.org>
2021-09-06 16:11:44stefanistratelinkissue45117 messages
2021-09-06 16:11:44stefanistratecreate