type annotations for xpath list

Martin Alaçam martinalacam at gmail.com
Wed Apr 8 18:02:37 EDT 2020


Hello,

I have the following descriptor:

    self._pi = None
    @property
    def pi(self) -> list:
        self._pi = self._root.xpath('processing-instruction()')
        return self._pi

Mypy says: "Incompatible return value type (got "None", expected
"List[Any]")"
The xpath expression always returns a list, if it doesn't find anything it
is an empty list. I am just getting started with type hinting, would
appreciate any help.

Best regards,


More information about the Python-list mailing list