问题描述
我在使用 mypy 和 lxml 存根时遇到问题。这个简化的代码重现了我在我的项目上运行 mypy 时看到的错误。
from lxml import etree
def fcn() -> None:
namespaces = {"a": "http://www.w3.org/2001/XMLSchema"}
etree.Element(
"{{{scl_namespaces['xs']}}}pattern",attrib={"value": "0"},nsmap=namespaces
)
if __name__ == "__main__":
fcn()
产生以下错误。
c:\>mypy --strict -m lxml_mypy
lxml_mypy.py:7: error: Argument "nsmap" to "Element" has incompatible type "Dict[str,str]"; expected "Union[Dict[Optional[bytes],bytes],Dict[Optional[str],str],None]"
Found 1 error in 1 file (checked 1 source file)
我正在使用:
- python 3.9.5
- lxml 4.6.3
- lxml 存根 0.2.0
我进行了一些搜索并找到了 TypeVar 和 TypedDict,但它们似乎都无法解决问题。有人对如何解决此输入错误有任何建议吗?
我还向 lxml-stubs
repo 提交了一个问题,他们建议询问 mypy 人员。我想在我在那个 repo 中提出问题之前我会在这里问。
如果您需要更多信息,请告诉我,并提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)