-
Notifications
You must be signed in to change notification settings - Fork 5
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.HtmlMixin
methods and properties are merged intoHtmlElement
. -
HtmlComment
andHtmlEntity
used to be a subclass ofHtmlMixin
; now they inherit fromHtmlElement
instead. (Marked in pink, see 2nd diagram below) -
HtmlProcessingInstruction
is completely removed.
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.html
andlxml.objectify
package 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.