Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def is_repeat(e: SurveyElement) -> bool:
if reference_parent:
# The LCAR may or may not be the closest ancestor repeat for source or target,
# but there's always at least the LCAR, so a check for None isn't needed.
source_car, _ = next(source.iter_ancestors(condition=is_repeat), None)
target_car, _ = next(target.iter_ancestors(condition=is_repeat), None)
source_car, _ = next(source.iter_ancestors(condition=is_repeat), (None, None))
target_car, _ = next(target.iter_ancestors(condition=is_repeat), (None, None))
# May return None if LCAR is a child of the Survey, or only non-repeating group(s).
lcar_not_in_repeat = next(lcar.iter_ancestors(condition=is_repeat), None) is None

Expand Down
18 changes: 7 additions & 11 deletions pyxform/survey_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def __setattr__(self, key, value):
self._survey_element_xpath = None
super().__setattr__(key, value)

def __repr__(self):
return f"""{super().__repr__()}(name="{self.name}")"""

def __init__(
self,
name: str,
Expand Down Expand Up @@ -195,13 +198,6 @@ def lowest_common_ancestor(
"""
Get the relation type, steps from self, steps from other, and the common ancestor.
"""

# Quick check for immediate relation.
if self.parent is other:
return "Parent (other)", 1, 0, other
elif other.parent is self:
return "Parent (self)", 0, 1, self

# Filtering
if group_type:
type_filter = {group_type}
Expand All @@ -211,10 +207,10 @@ def lowest_common_ancestor(
# Traversal tracking
self_ancestors = {}
other_ancestors = {}
self_current = self
other_current = other
self_distance = 0
other_distance = 0
self_current = self.parent
other_current = other.parent
self_distance = 1
other_distance = 1
lca = None

# Traverse up both ancestor chains as far as necessary.
Expand Down
Loading
Loading