您好,我正在尝试使用
types-lxml
库输入提示 lxml 返回类型。
def parse_xml(path: str) -> etree._ElementTree:
return etree.parse(path)
def components(path: str) -> List[etree._Element]:
return parse_xml(path).xpath("/node1/node2")
但是 mypy 对第二个函数抱怨说:
error: Returning Any from function declared to return "List[_Element]" [no-any-return]
知道如何解决这个问题吗?谢谢。
xpath 返回一个列表:
import lxml.etree
import mypy
# filecontent ="""<root><child>name</child>><child>name1</child></root>"""
def parse_xml(path: str) -> lxml.etree._ElementTree:
return etree.parse(path)
def components(path: str) -> list():
return parse_xml(path).xpath("/root/child")
r = parse_xml("./temp/example.xml")
print(type(r))
c = components("./temp/example.xml")
print(type(c))