dirtyhand-tester Python `from __future__ import annotations` 有人知道可以用来做什么吗?
simonpatrick
·
December 06, 2023
·
Last by TestNovice replied at December 14, 2023
·
7708 hits
Python from __future__ import annotations
有人知道可以用来做什么吗?
from __future__ import annotations
from __future__ import annotations
class A:
def __init__(self, b: B):
self.b = b
class B:
def __init__(self, a: A):
self.a = a
上面这个例子,如果不用from __future__ import annotations
就会报错,用了就不报错.
转载文章时务必注明原作者及原始链接,并注明「发表于 TesterHome 」,并不得对作品进行修改。
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!