Skip to content
Merged
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: 3 additions & 1 deletion src/gt4py/next/ffront/source_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

def get_closure_vars_from_function(function: Callable) -> dict[str, Any]:
(nonlocals, globals, builtins, _unbound) = inspect.getclosurevars(function) # noqa: A001 [builtin-variable-shadowing]
return {**builtins, **globals, **nonlocals} # nonlocals override globals

# nonlocals override globals, sorted for deterministic results
return dict(sorted({**builtins, **globals, **nonlocals}.items()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return dict(sorted({**builtins, **globals, **nonlocals}.items()))
return dict(sorted({**builtins, **globals, **nonlocals}.items(), key=lambda v: v[0]))

Otherwise it's also doing __lte__ on the values right? I'm surprised this works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't compare the second element of the tuple (values) unless the first (keys) are equal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So not sure if my version is considered canonical @egparedes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah and since they are unique it only considers the first one. I'd still use the key for clarity, but both fine with me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @havogt is the standard one, since we are sure that all keys are different.



def make_source_definition_from_function(func: Callable) -> SourceDefinition:
Expand Down