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

541 oc.select #687

Merged
merged 1 commit into from
Apr 18, 2021
Merged

541 oc.select #687

merged 1 commit into from
Apr 18, 2021

Conversation

omry
Copy link
Owner

@omry omry commented Apr 17, 2021

Closes #541

@omry omry requested review from odelalleau and Jasha10 and removed request for odelalleau April 17, 2021 02:05
@omry omry requested a review from odelalleau April 17, 2021 02:17
Copy link
Collaborator

@odelalleau odelalleau left a comment

Choose a reason for hiding this comment

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

Behavior looks good, just a few small things

docs/source/custom_resolvers.rst Outdated Show resolved Hide resolved
docs/source/custom_resolvers.rst Outdated Show resolved Hide resolved
docs/source/custom_resolvers.rst Outdated Show resolved Hide resolved
docs/source/custom_resolvers.rst Outdated Show resolved Hide resolved
docs/source/usage.rst Outdated Show resolved Hide resolved
Comment on lines 97 to 108
def select(
key: str,
default: Any = _DEFAULT_SELECT_MARKER_,
*,
_parent_: Container,
) -> Any:
from omegaconf._impl import select_value

if default is _DEFAULT_SELECT_MARKER_:
return select_value(cfg=_parent_, key=key, absolute_key=True)
else:
return select_value(cfg=_parent_, key=key, absolute_key=True, default=default)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use a different marker?

Suggested change
def select(
key: str,
default: Any = _DEFAULT_SELECT_MARKER_,
*,
_parent_: Container,
) -> Any:
from omegaconf._impl import select_value
if default is _DEFAULT_SELECT_MARKER_:
return select_value(cfg=_parent_, key=key, absolute_key=True)
else:
return select_value(cfg=_parent_, key=key, absolute_key=True, default=default)
def select(
key: str,
default: Any = _DEFAULT_MARKER_,
*,
_parent_: Container,
) -> Any:
from omegaconf._impl import select_value
return select_value(cfg=_parent_, key=key, absolute_key=True, default=default)

Copy link
Owner Author

Choose a reason for hiding this comment

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

good point. Initially I was passing it into select_value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it can be simplified further (see my suggestion: no more if)

Copy link
Owner Author

Choose a reason for hiding this comment

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

yeah, for some reason I thought using the same marker object select_value is using would cause issues.

docs/source/custom_resolvers.rst Show resolved Hide resolved
tests/interpolation/built_in_resolvers/test_oc_select.py Outdated Show resolved Hide resolved
tests/interpolation/built_in_resolvers/test_oc_select.py Outdated Show resolved Hide resolved
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.

Looks good :)
Just one grammar nit-pick beyond Olivier's suggestions:

docs/source/custom_resolvers.rst Outdated Show resolved Hide resolved
@omry omry merged commit 45ee52e into master Apr 18, 2021
@omry omry deleted the 541-oc.select branch April 18, 2021 00:33
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.

Allow "default" in interpolation when target config node does not exist
3 participants