def get_imports_for_signature(sig: inspect.Signature) -> ImportMap:
"""Return the imports (module, name) needed for all types in annotations"""
imports = ImportMap()
for param in sig.parameters.values():
param_imports = get_imports_for_annotation(param.annotation)
imports.merge(param_imports)
return_imports = get_imports_for_annotation(sig.return_annotation)
imports.merge(return_imports)
return imports
评论列表
文章目录