键入 "hashable" 的提示
Type hint for "hashable"
有时我编写的函数的参数可以是任何类型,只要它是 hashable - 例如,因为我的函数将它添加到集合中或将其用作字典键。
有没有办法使用 Python 3.5 中引入的 PEP 484 类型提示来对这一事实进行类型提示? typing
模块似乎不包含可散列类型,但还有其他方法吗?
typing
模块 实际上包含一个 Hashable
type (now documented). It's an alias for collections.abc.Hashable
。
>>> import typing
>>> typing.Hashable
<class 'collections.abc.Hashable'>
有时我编写的函数的参数可以是任何类型,只要它是 hashable - 例如,因为我的函数将它添加到集合中或将其用作字典键。
有没有办法使用 Python 3.5 中引入的 PEP 484 类型提示来对这一事实进行类型提示? typing
模块似乎不包含可散列类型,但还有其他方法吗?
typing
模块 实际上包含一个 Hashable
type (now documented). It's an alias for collections.abc.Hashable
。
>>> import typing
>>> typing.Hashable
<class 'collections.abc.Hashable'>