Skip to content

Commit

Permalink
Add "__getattr__()" method to ObjectifiedElement to support arbitrary…
Browse files Browse the repository at this point in the history
… attribute lookups.

Closes #61
  • Loading branch information
scoder committed Mar 4, 2022
1 parent 0b1659f commit d29a5ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lxml-stubs/objectify.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
13 changes: 13 additions & 0 deletions test-data/test_objectify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- case: etree_from_string_returns_element
disable_cache: true
main: |
from lxml import objectify
document = objectify.fromstring("<doc></doc>")
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("<doc><xyz/></doc>").xyz
reveal_type(xyz) # N: Revealed type is "lxml.objectify.ObjectifiedElement"

0 comments on commit d29a5ee

Please sign in to comment.