[Python] Type hints for lxml.etree._Element

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I often work with the lxml and my IDE (PyCharm 2021.2.2) warns me about accessing a protected member of the module in my type hints because many of my function use lxml.etree._Element as inputs or outputs. But as many functions of lxml.etree returns _Element objects I think it must be normal to use them.

    For example this code

    from lxml import etree

    root = etree.parse(r"C:\xmlfile.xml").getroot()
    print(type(root))


    prints : <class 'lxml.etree._Element'>




    What should I do to get rid of those warnings ? Should I configure my IDE to ignore them or is there a cleaner way to make the type hints ?

    [​IMG]

    Continue reading...

Compartilhe esta Página