eclipse-basyx / basyx-python-sdk

MIT License
60 stars 28 forks source link

add `lxml` typechecking #279

Closed jkhsjdhjs closed 4 months ago

jkhsjdhjs commented 4 months ago

lxml provides type annotations via the lxml-stubs package. By using this package, we don't need the type: ignore comments when importing lxml anymore. Furthermore, the typehints are adjusted: etree.Element is only a factory function that creates etree._Element instances.

Finally, when generating the docs we introduced a workaround that makes linking to the lxml documentation possible. Since it only replaced lookups for Element with _Element, it isn't necessary anymore and removed.

s-heppner commented 4 months ago

So you're saying that by default, every user of lxml should access the internal class etree._Element? That seems weird to me.

jkhsjdhjs commented 4 months ago

Every user of lxml is implicitly working with _Element, as Element is just a factory function that returns _Element instances. It's also a bit weird to me, but that's the way it is implemented.

See also: https://stackoverflow.com/questions/76321801/type-hints-for-lxml-etree-element#comment134587997_76321801

s-heppner commented 4 months ago

Okay, then I'm fine that we use etree._Element for the type annotation, as long as we still call etree.Element() to instantiate.