Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug[eve]: Preserve annex None value in visitors #1508

Merged
merged 2 commits into from
Mar 21, 2024
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
2 changes: 1 addition & 1 deletion src/gt4py/eve/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def generic_visit(self, node: concepts.RootNode, **kwargs: Any) -> Any:
# access to `new_node.annex` implicitly creates the `__node_annex__` attribute in the property getter
new_annex_dict = new_node.annex.__dict__
for key in self.PRESERVED_ANNEX_ATTRS:
if value := getattr(old_annex, key, None):
if (value := getattr(old_annex, key, NOTHING)) is not NOTHING:
assert key not in new_annex_dict
new_annex_dict[key] = value

Expand Down
8 changes: 5 additions & 3 deletions tests/eve_tests/unit_tests/test_visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

def test_annex_preservation(compound_node: eve.Node):
compound_node.annex.foo = 1
compound_node.annex.bar = 2
compound_node.annex.bar = None # None is easily forgotten so test seperately
compound_node.annex.baz = 2

class SampleTranslator(eve.NodeTranslator):
PRESERVED_ANNEX_ATTRS = ("foo",)
PRESERVED_ANNEX_ATTRS = ("foo", "bar")

translated_node = SampleTranslator().visit(compound_node)

assert translated_node.annex.foo == 1
assert not hasattr(translated_node.annex, "bar")
assert translated_node.annex.bar is None
assert not hasattr(translated_node.annex, "baz")
Loading