lxml / lxml-stubs

Type stubs for the lxml package
Other
43 stars 29 forks source link

Some etree methods define keyword args as args #85

Closed frabarz closed 1 year ago

frabarz commented 1 year ago

I'm using VSCode with pylance enabled. Having a node: lxml.etree._Element, I'm trying to use the method node.iterchildren("InlineTable", "Table", "TableUsage"), but the type checker complains about the "Table" argument:

Argument of type "Literal['Table']" cannot be assigned to parameter "reversed" of type "bool" in function "iterchildren"
  "Literal['Table']" is incompatible with "bool"

Seems like many of the methods in etree.pyi are defined with the *tags argument at the end, like this:

def iterchildren(
    self,
    tag: Optional[_TagSelector] = ...,
    reversed: bool = False,
    *tags: _TagSelector,
) -> Iterable[_Element]: ...

while the code definition in the lxml repository is:

def iterchildren(self, tag=None, *tags, reversed=False):

This means the reversed argument is actually a keyword argument, and calls would result in:

node.iterchildren("Table", True) # True in tags, reversed is False
node.iterchildren("Table", reversed=True) # reversed is True
node.iterchildren("Table", "InlineTable", True) # True in tags
node.iterchildren("Table", "InlineTable", reversed=True) # reversed is True
scoder commented 1 year ago

Thanks. Fixed.