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

Improved handling of None values in node validation #592

Merged
merged 8 commits into from
Mar 10, 2021

Conversation

odelalleau
Copy link
Collaborator

This PR extracts some of the changes from #578, related to the handling of None values.

Note that the test test_none_value_in_quoted_string added here is not directly related to these changes (since it worked before this PR too), but it is good to have this test in before #578.

Copy link
Owner

@omry omry left a comment

Choose a reason for hiding this comment

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

Overall looks ok.
A few inline comments.

Also, are there any known bugs this is fixing? If so, can you add corresponding tests?

def test_none_value_in_quoted_string(restore_resolvers: Any) -> None:
OmegaConf.register_new_resolver("test", lambda x: x)
cfg = OmegaConf.create({"x": "${test:'${missing}'}", "missing": None})
assert cfg.x == "None"
Copy link
Owner

Choose a reason for hiding this comment

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

okay, so quoting an interpolation is equivalent to casting the resolved value to a string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. To clarify, there are two situations:

  1. The interpolation is exactly surrounded by quotes ("${...}") => we resolve it normally but cast the result to string.
  2. There are other characters around the interpolation ("hello ${...} and hi") => this is strictly equivalent to regular string interpolations

I think this is the most intuitive behavior.

@odelalleau
Copy link
Collaborator Author

Also, are there any known bugs this is fixing?

No user-facing bug that I know of. This is why it was originally part of #578 after the interpolation type validation (because it was fixing bugs there)

This PR still adds some tests of validate_and_convert() that would have failed before.

Copy link
Collaborator

@Jasha10 Jasha10 left a comment

Choose a reason for hiding this comment

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

A few refactorings and type-signature changes:

odelalleau and others added 2 commits March 10, 2021 14:51
@odelalleau odelalleau merged commit f056ee6 into omry:master Mar 10, 2021
@odelalleau odelalleau deleted the validate_none branch March 10, 2021 22:31
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.

3 participants