[Python] Correct way to type hint protected / private classes in Python?

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

  1. Stack

    Stack Membro Participativo

    I have a sample class here that I would like to use lxml to parse xml files.

    class XMLParser:

    def __init__(self, path: str):
    self.root: etree._Element | None = None


    However, PyCharm complains about access to a protected member _Element when I use this type hint. Is there a more correct way to annotate such a variable? The _Element class is the correct one when I type check this.

    Thanks for your help!

    Continue reading...

Compartilhe esta Página