Iny*_*Kim 0 python class type-hinting
class Session:
@staticmethod
def load_from_json(json_path:str) -> Session:
pass
Run Code Online (Sandbox Code Playgroud)
上面抛出一个NameError: name 'Session' is not defined. 在其定义中使用自身作为类型提示是不可能的吗?
使用:
def ... -> 'Session':
Run Code Online (Sandbox Code Playgroud)
使用时Session没有定义,所以必须使用字符串(Python 3.8)。
| 归档时间: |
|
| 查看次数: |
717 次 |
| 最近记录: |