简体   繁体   中英

How to define an alias for a type in Python for type hinting

How to define an alias for a type to use type hint:

import typing
type Ticker str # How to do this? I used golang notation. How do you do it in python?
Report = typing.Dict[Ticker, typing.List] 

Which means Ticker is a type of string and Report is a dict from Ticker to a list. Thank you. The good thing about this aliasing is that anyone knows that it is a ticker. Much clear and more readable than writing Report = typing.Dict[str, typing.List]

As you do with all other names that you bind to objects:

Ticker = typing.Text

See https://docs.python.org/3/library/typing.html#type-aliases

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