简体   繁体   中英

Python type aliases without typing module TypeError: 'type' object is not subscriptable

I was previously using from typing import Dict, List etc. but saw https://docs.python.org/3/library/typing.html give example type aliases as

ConnectionOptions = dict[str, str] Address = tuple[str, int] Server = tuple[Address, ConnectionOptions]

When I tried in my own code

MyType = list[tuple[int, list[int]]]

I got

TypeError: 'type' object is not subscriptable

Is it still not possible to use lowercase type names for typehints? If it is, how can I successfully do it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM