I am trying to use mypy to check my codebase and I can't fix the following error.
It seems to be an issue with lxml and namespaces - the below XML makes use of the junos namespace for the junos:changed attribute:
<interfaces xmlns:junos="http://xml.juniper.net/junos/*/junos">
<interface>
<name>et-0/1/0</name>
<description junos:changed='changed'>## [DCI] 100GE Circuit to ROUTER-01 (et-0/1/0) ##</description>
</interface>
<interface>
<name>et-0/1/1</name>
<description>## 100GE Link to SPINE-01 (et-0/0/0) ##</description>
</interface>
<interface>
<name>et-0/1/2</name>
<description>## 100GE Link to SPINE-02 (et-0/0/0) ##</description>
</interface>
</interfaces>
I am then using the following Python code to perform an xpath query:
I am extracting the namespace from the XML and then passing it to the xpath query, but mypy complains about the following:
program.py:66: error: Argument "namespaces" to "xpath" of "_Element" has incompatible type "Dict[Optional[str], str]"; expected "Optional[Mapping[str, Union[str, bytes]]]" [arg-type]
Surely the output from one lxml function should be the required type to be used as input for another?
I am trying to use
mypy
to check my codebase and I can't fix the following error. It seems to be an issue withlxml
andnamespaces
- the below XML makes use of thejunos
namespace for thejunos:changed
attribute:I am then using the following Python code to perform an
xpath
query:I am extracting the namespace from the XML and then passing it to the
xpath
query, butmypy
complains about the following:Surely the output from one
lxml
function should be the required type to be used as input for another?Python 3.9 with the following:
mypy==1.0.0 lxml==4.9.2 types-lxml==2022.11.8