Skip to content

Commit d29a5ee

Browse files
committed
Add "__getattr__()" method to ObjectifiedElement to support arbitrary attribute lookups.
Closes #61
1 parent 0b1659f commit d29a5ee

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lxml-stubs/objectify.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from lxml.etree import ElementBase, XMLParser
66
def __getattr__(name) -> Any: ...
77

88
class ObjectifiedElement(ElementBase):
9-
pass
9+
def __getattr__(self, name) -> ObjectifiedElement: ...
1010

1111
def fromstring(
1212
text: Union[bytes, str],

test-data/test_objectify.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- case: etree_from_string_returns_element
2+
disable_cache: true
3+
main: |
4+
from lxml import objectify
5+
document = objectify.fromstring("<doc></doc>")
6+
reveal_type(document) # N: Revealed type is "lxml.objectify.ObjectifiedElement"
7+
8+
- case: etree_from_string_returns_element
9+
disable_cache: true
10+
main: |
11+
from lxml import objectify
12+
xyz = objectify.fromstring("<doc><xyz/></doc>").xyz
13+
reveal_type(xyz) # N: Revealed type is "lxml.objectify.ObjectifiedElement"

0 commit comments

Comments
 (0)