# 返回类示例
- 在 Python 3.10 或以上版本,直接返回类即可;
- Python 3.7+:
from __future__ import annotations
from __future__ import annotations
class Position:
def __add__(self, other: Position) -> Position:
...
- Python ❤️.7 版本: 使用类的
string形式
class Position:
...
def __add__(self, other: 'Position') -> 'Position':
...
- Exceptions 对于异常,目前没有建议列出显式引发的异常的语法。 而是建议将此信息文档化,放在代码的文档字符串中。 参阅:PEP 484 -- Type Hints | Python.org (opens new window)