Skip to content

mypy complains about list[_ElementUnicodeResult] type hint #75

@albertisfu

Description

@albertisfu

Hello! we recently updated to lxml-stubs 0.4.0 (using lxml 4.9.1) and got the following complaint from mypy:

html_tree = fromstring(content)
title = html_tree.xpath("//title/text()")
len(title)

Checking the type of title I got:
list[_ElementUnicodeResult]

But mypy complains:

error: Argument 1 to "len" has incompatible type "Union[bool, float, Union[_ElementUnicodeResult, _PyElementUnicodeResult, _ElementStringResult], Union[str, bytes], List[Union[_Element, Union[_ElementUnicodeResult, _PyElementUnicodeResult, _ElementStringResult], Union[str, bytes], Tuple[Union[str, bytes, None], Union[str, bytes, None]]]]]"; expected "Sized"

This problem is also in 0.3.1, so we had to downgrade to 0.2.0 where this problem is not present.

wondering if this is a bug to be solved?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions