From d29a5ee43cadd561aad5163078cebc5dd9a237ef Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 4 Mar 2022 10:36:57 +0100 Subject: [PATCH] Add "__getattr__()" method to ObjectifiedElement to support arbitrary attribute lookups. Closes https://github.com/lxml/lxml-stubs/issues/61 --- lxml-stubs/objectify.pyi | 2 +- test-data/test_objectify.yml | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test-data/test_objectify.yml diff --git a/lxml-stubs/objectify.pyi b/lxml-stubs/objectify.pyi index 9d76971..18303d8 100644 --- a/lxml-stubs/objectify.pyi +++ b/lxml-stubs/objectify.pyi @@ -6,7 +6,7 @@ from lxml.etree import ElementBase, XMLParser def __getattr__(name) -> Any: ... class ObjectifiedElement(ElementBase): - pass + def __getattr__(self, name) -> ObjectifiedElement: ... def fromstring( text: Union[bytes, str], diff --git a/test-data/test_objectify.yml b/test-data/test_objectify.yml new file mode 100644 index 0000000..3ddf5da --- /dev/null +++ b/test-data/test_objectify.yml @@ -0,0 +1,13 @@ +- case: etree_from_string_returns_element + disable_cache: true + main: | + from lxml import objectify + document = objectify.fromstring("") + reveal_type(document) # N: Revealed type is "lxml.objectify.ObjectifiedElement" + +- case: etree_from_string_returns_element + disable_cache: true + main: | + from lxml import objectify + xyz = objectify.fromstring("").xyz + reveal_type(xyz) # N: Revealed type is "lxml.objectify.ObjectifiedElement"