Merged
Conversation
Previously, when iter() encountered a non-Element child (like a text string), it would yield it unconditionally, even if the caller was searching for a specific tag (e.g., .//c).
```
def test_Element_findall_dotslashslash():
c1 = Element('c')
c2 = Element('c')
text = "text"
b1 = Element('b', children=(c1, text, c2))
b2 = Element('b')
a1 = Element('a', children=(b1, b2, ))
result = list(a1.findall('.//c'))
> assert len(result) == 2
E AssertionError: assert 3 == 2
E + where 3 = len([<Element 'c' at 1056c4450>, 'text', <Element 'c' at 1056c4810>])
src/emeraldtree/tests/test_tree.py:208: AssertionError
```
The fix ensures that non-Element children are only yielded if no tag filter is specified (tag is None).
- Implemented 1-based indexing for predicates (e.g. tag[1]). - Raise SyntaxError for invalid indices (< 1) to match xml.etree behavior. - Enabled test_Element_findall_position and added test_Element_findall_position_invalid.
Closed
Member
Author
|
.// and [position] are the same as in #18. .. parent selector is a simpler implementation that shares the same design limitation as the elementtree code in stdlib, tests adapted accordingly. |
Build a temporary parent_map dynamically in prepare_dot_dot by iterating from context.root, matching stdlib ElementTree's approach. New: skip non-iterable children (text nodes) when building the map. Like stdlib, ../tag returns empty when called from a leaf element that has no ancestor context. Paths like b/../c work correctly when called from a higher element that contains the full subtree.
0ebdf95 to
fb251b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.