#!/usr/bin/env python3
def updateAnnotations(annotations, bases):
for base in bases:
annotations.update(getattr(base, '__annotations__', dict()))
class A:
valA: int
class B:
valB: int
class C(A, B):
valC: int
updateAnnotations(__annotations__, [A, B])
print(sorted(C.__annotations__.items()))
想法:
输出:
使用装饰器:
输出:
相关问题 更多 >
编程相关推荐