-
Notifications
You must be signed in to change notification settings - Fork 2
Treat default values in function signature the same way as config kwargs #12
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -913,5 +913,67 @@ def func(x): | |
| cfn.Config(func, '.return1') | ||
|
|
||
|
|
||
| def test_config_config_default_values_are_resolved_properly(): | ||
|
|
||
| @cfn.config() | ||
| def return1(): | ||
| return 1 | ||
|
|
||
| @cfn.config() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this PR mean that there's no need to have cfn.config decorator as a function (aka decorator factory) and we can just make it a usual decorator? |
||
| def add1(a=return1): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we imagine the non-config-decorated functions that take configs as arguments? What I want to say is that I don't like passing configs as defaults to functions. I would propose to pass configs as defaults only to config decorators. Otherwise, the reader can really be confused, as the real default is not the config, but its instantiation. |
||
| return a + 1 | ||
|
|
||
| assert add1.instantiate() == 2 | ||
|
|
||
|
|
||
| def test_config_config_multiple_default_values_are_resolved_properly(): | ||
|
|
||
| @cfn.config() | ||
| def returnx(x=1): | ||
| return x | ||
|
|
||
| return1 = returnx.override(x=1) | ||
| return2 = returnx.override(x=2) | ||
|
|
||
| @cfn.config() | ||
| def add1(a, b=return1, c=return2): | ||
| return f"{a} + {b} + {c}" | ||
|
|
||
| assert add1(a=0) == "0 + 1 + 2" | ||
|
|
||
|
|
||
| def test_config_default_function_kwargs_are_overriden_by_config_kwargs(): | ||
| @cfn.config() | ||
| def return1(): | ||
| return 1 | ||
|
|
||
| @cfn.config() | ||
| def return2(): | ||
| return 2 | ||
|
|
||
| @cfn.config(a=return1) | ||
| def add1(a=return2): | ||
| return a + 1 | ||
|
|
||
| assert add1.instantiate() == 2 | ||
|
|
||
|
|
||
| def test_config_args_and_kwargs_kwargs_are_overriden_by_config_kwargs(): | ||
| @cfn.config() | ||
| def return1(): | ||
| return 1 | ||
|
|
||
| @cfn.config() | ||
| def return2(): | ||
| return 2 | ||
|
|
||
| def func(*args, b=return2): | ||
| return f"{args} + {b}" | ||
|
|
||
| func = cfn.Config(func, 1, 2, b=return1) | ||
|
|
||
| assert func.instantiate() == "(1, 2) + 1" | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| pytest.main() | ||
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 think we need to expand the other sections (particularly resolution and relative resolution) to document this new functionality