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

Attempt at making substitutions work inside dicts and lists. #269

Merged
merged 6 commits into from
Apr 10, 2024

Conversation

JSKenyon
Copy link
Collaborator

@JSKenyon JSKenyon commented Mar 28, 2024

This PR aims to improve substitutions by supporting them inside compound types. This probably needs extensive testing, but the following should now work:

inputs:
  foo:  # foo is Dict[str, Tuple[File, float, str]] type.
    bar: [=expression_with_substitution, 1, example]  

or equivalently:

inputs:
  foo:   # foo is Dict[str, Tuple[File, float, str]] type.
    bar: =LIST(substitution, 1, "example")

This should also support more complicated cases e.g.:

inputs:
  foo:   # foo is List[Dict[str, Tuple[File, float, str]]] type.
    bar: 
      - baz: [=expression_with_substitution, 1, example]

@JSKenyon JSKenyon requested a review from o-smirnov March 28, 2024 10:34
recursive,
verbose
)
elif isinstance(value, list):
Copy link
Member

Choose a reason for hiding this comment

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

@JSKenyon clever, clever. Maybe use (list, ListConfig) just in case?

Copy link
Member

Choose a reason for hiding this comment

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

Even better:

params_out[name] = type(value)([x for x in
    self.evaluate_dict({f"[{i}]": v for i, v in enumerate(value)}, ...).values()
   ])

...because then any nested error messages will report the location of the error sensibly as "[n]".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, awesome. Definitely better than a profusion of dummies!

Copy link
Member

Choose a reason for hiding this comment

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

Actually no need for the extra list comprehension, right? This should work too:

type(value)(self.evaluate_dict({f"[{i}]": v for i, v in enumerate(value)}, ...).values())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I have made a final change. Let me know if it appeals.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, also the evaluate_dict() call needs sublocation=sublocation + [name], so that errors are reported from the correct nested namespace.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for making those changes @o-smirnov - was only going to get to it today.

@o-smirnov o-smirnov linked an issue Apr 2, 2024 that may be closed by this pull request
@o-smirnov o-smirnov merged commit 2e786b2 into master Apr 10, 2024
3 checks passed
@o-smirnov o-smirnov deleted the nested_subs branch April 10, 2024 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

logs from nested recipe steps not propagated to console
3 participants