# 返回类示例

  • 在 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':
       ...

参阅:python - How do I type hint a method with the type of the enclosing class? - Stack Overflow (opens new window)

# 相关链接