[issue45117] `dict` not subscriptable despite using `__future__` typing annotations
Dennis Sweeney
report at bugs.python.org
Tue Sep 7 00:48:42 EDT 2021
Dennis Sweeney <sweeney.dennis650 at gmail.com> added the comment:
Hi Stefan,
`from __future__ import annotations` only affects annotations -- just the things after the colon. It makes it so that annotations are never evaluated, so things like this work:
>>> from __future__ import annotations
>>> x: nonsense()()()()[other_nonsense](1<2>3)
The __future__ import is not a wholesale opt-in-to-all-new-typing-features, it's just an opt-in-to-not-evaluate-annotations.
dict.__class_getitem__ (which is what gets called when you type dict[str, Any]) was not added at all until Python 3.9 (GH-18239), so if you want to *evaluate* such expressions, you have to upgrade to 3.9+. In 3.8, use typing.Dict instead -- 3.8 is no longer accepting new features.
Thanks for the report, but I'm closing this for now.
----------
nosy: +Dennis Sweeney
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45117>
_______________________________________
More information about the Python-bugs-list
mailing list