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

Allow typed dictionaries, and dictionary subscripts from expander #799

Merged

Conversation

douglasjacobsen
Copy link
Collaborator

This merge enables the expander to handle dictionaries better.

The most obvious change from this is that given:

variables:
  test_dict:
    key1: val1
    key2: val2

then '{test_dict["key1"]}' should expand to "val1".

A more subtle change from this is that given the variable definition above, inside object definitions one can now do:

test_dict = app_inst.expander.expand_var_name("test_dict", typed=True)

for key, val in test_dict.items():
  print(f"Key {key} = {val}")

Tests and documentation have also been added for this.

@douglasjacobsen douglasjacobsen added the enhancement New feature or request label Dec 12, 2024
@douglasjacobsen douglasjacobsen force-pushed the expander-dictionaries branch 2 times, most recently from 438ff19 to f4f3e8b Compare December 12, 2024 19:43
This commit adds the ability for the expander to return a typed
dictionary based on variable definitions.

Subscripting of dictionaries will also return the value of the key, from
the expander now.
i.e. `'{dict["key"]}'` will return the value of the key.
This commit updates the error handling in the expander ast logic so that
SyntaxErrors trigger a debug print before being raised again (and
causing an unexpanded string to be returned)
This commit unifies the handling of generic SyntaxErrors in Ramble's
expander. This allows all SyntaxErrors to print debugging information,
which can be useful in determining why the expander behaves the way it
does.
@rfbgo rfbgo merged commit b6f4fc3 into GoogleCloudPlatform:develop Dec 13, 2024
12 checks passed
@douglasjacobsen douglasjacobsen deleted the expander-dictionaries branch January 9, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants