在编写类的接口的时候 如何指明参数类型为本类
class A():
def __init__(self):
pass
def func(pra1:A):
pass
这种情况下,在def func(par1:A) 中的A会报错,因为类A没有生成。请问这这种如何解决
For different versions of Python
In Python 3.6 or below, you should use a string -
'A'
In Python 3.7 ~ 3.10, you can add statement
from __future__ import annotations
In Python 3.11+, you can use
from typing import Self
, then usedef func(pra1:Self):