如何在定义函数期间创建一个提示,该提示将指示 returns 的非典型对象?
How to create a hint during defining the function which would indicates untypical object which returns?
我正在尝试定义函数,该函数指示 returns 对象类型
hashlib.sha256(b'password')
明确地说我想做的是:def encrypt(self, password: str) -> _hashlib.HASH:
不幸的是,_hashlib.HASH" 无法被我的解释器正确读取,出现未知对象错误。如何处理?
将此添加到模块的顶部:
from __future__ import annotations
会postpone evaluation of the annotation。这将成为 Python 3.10 中的默认行为。
我正在尝试定义函数,该函数指示 returns 对象类型
hashlib.sha256(b'password')
明确地说我想做的是:def encrypt(self, password: str) -> _hashlib.HASH:
不幸的是,_hashlib.HASH" 无法被我的解释器正确读取,出现未知对象错误。如何处理?
将此添加到模块的顶部:
from __future__ import annotations
会postpone evaluation of the annotation。这将成为 Python 3.10 中的默认行为。