-
Notifications
You must be signed in to change notification settings - Fork 910
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
Modify KedroContext
with frozen attributes instead of frozen class
#3300
Conversation
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@astrojuanlu I think this should work, however I am stuck with a testing issue. There are two problems
mock_cls = create_attrs_autospec(KedroContext) If you inspect this object you should see that all attributes are there, yet if you look at the test it complains
|
I manage to fix the test. @Galileo-Galilei Any chance you can test with this branch? |
I'll do it tonight |
Generally this looks good to me. In the description you asked:
I 100% agree this order looks arbitrary now, especially because there's a mix of "internal"/"private" arguments starting with |
Hi @noklam and thank for adressing it! I haven't looked at the code in detail yet, but I have tested the behaviour and it works as expected:
I agree that it is likely time to reorder all arguments to make clearer which one are public. However, I still have more generic concerns on whether all (or even any) attributes should be frozen. The I can also think of use cases in which I want to update the By order of preference:
|
I have decided to not freeze any attribute at the end. Choosing some attributes to freeze and not others feels arbitrary to me, let's just fallback to Python convention with Additionally, I re-arrange the order of the argument. Noted that |
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Galileo-Galilei for testing and explaining your pain points. This is really insightful. I agree with the approach to not freeze anything in the end @noklam 👍
I was just wondering if you then still need all the tests for checking attributes?
@@ -158,18 +158,38 @@ def _expand_full_path(project_path: str | Path) -> Path: | |||
return Path(project_path).expanduser().resolve() | |||
|
|||
|
|||
@frozen | |||
@define(slots=False) # Enable setting new attributes to `KedroContext` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed now we're not freezing anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just wondering if you then still need all the tests for checking attributes?
It is needed, and for this reason I keep one of the test. If you try to set slots=True
(or remove this argument since it's default), you will see the test fail. The default for standard Python library is False
https://www.attrs.org/en/stable/api.html#attrs.define - The reason for this is slotted class is more efficient and make sense if it is used as "dataclass" (think of pydantic model that get convert to JSON etc), in this case it's irrelevant
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @noklam for revisiting this change, good thing we didn't release it the way it was 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @noklam 😄
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Thank you everyone and especially @noklam for this change, and sorry for not having been as available as I had wanted to to help for this! |
…3300) * modify release note Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * Make KedroContext partial frozen Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * fix KedroContext and add test for public and internal attributes Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * Fix tests Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * Rearrange the `KedroContext` arguments Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * improve test_set_new_attribute Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * Unfreeze the Kedrocontext attributes Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * clean up Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * remove redundant test Signed-off-by: Nok <nok.lam.chan@quantumblack.com> --------- Signed-off-by: Nok <nok.lam.chan@quantumblack.com> Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com> Signed-off-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Signed-off-by: Nok nok.lam.chan@quantumblack.com
Description
Fix #1459. Initially we plan to freeze the class to prevent users changing the internal details. After some discussion, this can be too restrictive and we decide to only freeze existing attributes. Users are free to create their own as long as it doesn't conflict with the internal one.
Development notes
For Reviewer
Looking at the current interface, should we re-order the argument as it seems arbitary, (and) maybe make it keyword only.
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
RELEASE.md
file