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

Fix OmegaConfigLoader __repr__ and missing keys method #4030

Merged
merged 8 commits into from
Jul 26, 2024

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Jul 25, 2024

Description

Fix #3618, since we are trying to improve the interactive experience. While it's still a bit unclear as AbstractConfigLoader inherit from UserDict, OmegaConfigLoader only presents traits for dictionary access pattern, i.e. dict["key"], but not the other API such as iterating the keys.

Development notes

The PR is not a perfect fix, but nonetheless address two issues:

  1. __repr__ is misleading as it is missing some arguments to start with, to do this I also have to save self._custom_resolver)
  2. keys is implemented so that at least it is iterable, we can consider __iter__ and values as well but I want to keep this PR minimal.

Before change

image

After change

image

Developer Certificate of Origin

We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a Signed-off-by line in the commit message. See our wiki for guidance.

If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.

Checklist

  • Read the contributing guidelines
  • Signed off each commit with a Developer Certificate of Origin (DCO)
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes
  • Checked if this change will affect Kedro-Viz, and if so, communicated that with the Viz team

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam noklam requested a review from merelcht as a code owner July 25, 2024 09:36
@noklam noklam requested review from ankatiyar and ElenaKhaustova and removed request for ankatiyar July 25, 2024 09:36
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam noklam requested a review from ankatiyar July 25, 2024 09:45
@noklam
Copy link
Contributor Author

noklam commented Jul 25, 2024

I get this error when the dictionary return a list[str], I don't know why this is important as I found it annoying you always have to do list(keys) to see the real content (unlike dict.keys()`, but this seems to be what Python suggest to do so I am following the convention here. https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects

mypy kedro --strict --allow-any-generics --no-warn-unused-ignores
kedro/config/omegaconf_config.py:267: error: Return type "list[str] | None" of "keys" incompatible with return type "KeysView[Any]" in supertype "Mapping" [override]

As a result it shows:

In [25]: KeysView(c.config_patterns)
Out[25]: KeysView({'catalog': ['catalog*', 'catalog*/**', '**/catalog*'], 'parameters': ['parameters*', 'parameters*/**', '**/parameters*'], 'credentials': ['credentials*', 'credentials*/**', '**/credentials*'], 'globals': ['globals.yml']})

In [26]: p = c.config_patterns

In [27]: list(KeysView(p))
Out[27]: ['catalog', 'parameters', 'credentials', 'globals']

I don't find this particular valuable, but this seems to be the only way to please mypy,

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Copy link
Contributor

@ElenaKhaustova ElenaKhaustova left a comment

Choose a reason for hiding this comment

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

Approving with a question, the rest LGTM!

RELEASE.md Outdated Show resolved Hide resolved
RELEASE.md Outdated Show resolved Hide resolved
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam noklam enabled auto-merge (squash) July 26, 2024 11:25
@noklam noklam merged commit 6609455 into main Jul 26, 2024
41 checks passed
@noklam noklam deleted the noklam/omegaconfig-print branch July 26, 2024 11:47
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.

OmegaConfigLoader's __repr__ is not implemented correctly, and it does not behave similar to a UserDict
3 participants