如何为 Python 中的类型定义别名以进行类型提示

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

如何为类型定义别名以使用类型提示:

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] 

这意味着Ticker是一种字符串类型,而Report是从Ticker到列表的dict。谢谢你。 这种别名的好处是任何人都知道它是一个自动收报机。比写 Report = typing.Dict[str, typing.List]

更清晰,更易读

正如您对绑定到对象的所有其他名称所做的那样:

Ticker = typing.Text

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