-
Notifications
You must be signed in to change notification settings - Fork 8
Element inheritance change
Since release 2023.3.28, some incompatible change of
lxml Element inheritance is introduced, primarily intended
to simplify type checking usage.
-
lxml.html.HtmlMixinmethods and properties are merged intoHtmlElement. -
HtmlCommentandHtmlEntityused to be a subclass ofHtmlMixin; now they inherit fromHtmlElementinstead. (Marked in pink, see 2nd diagram below) -
It is restored sinceHtmlProcessingInstructionis completely removed.2024.02.09version upon user request
One of the biggest surprise for annotation is that, though
_Comment, _PI and _Entity are inherited from _Element,
the HTML counterparts are not true for HtmlElement —
they exist independently.
Their common denominator is a mixin class (HtmlMixin), which
unfortunately contains quite a few methods / properties that only
make sense in HtmlElement (for example, HtmlComment never
contains any class attribute nor associates with any label element).
lxml.etree._Element and their descendants in source code
can be illustrted by following abirdged diagram.
- Most prominent element classes from each package are colored in teal.
-
lxml.htmlandlxml.objectifypackage are stripped down for simplicity, subelements from these subpackages do not play any important role in the topic discussed here.

Following diagram illustrates how inheritance is changed in types-lxml stub.

Please visit this gist to access all UML source of diagrams as well as their description.