-
Notifications
You must be signed in to change notification settings - Fork 431
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
How should we pass / control kwargs ? #354
Comments
Some things I think don't need to be solved by papermill are situations like: def foo(a, **kwargs):
pass
foo(1, a=3) If you end up in a place where this is a problem that needs solving I think it is a sign that we need to backup and take a different direction somewhere earlier. If this happens the solution is documentation (I think). I think for passing additional (keyword) arguments to engines we should change
which users can then call as There is one wrinkle: some arguments need translating ( I think this can be solved by documentation that explains "the argument you call As an alternative you could pick out that value and use it, something like this ( # you say timeout, we say execution_timeout
execution_timeout = extra_engine_args.pop("timeout", execution_timeout)
preprocessor = PapermillExecutePreprocessor(
timeout=execution_timeout,
...
**extra_engine_args
): and do the translation for the user. |
Agree with @betatim that parameters we overwrite or renamed should be documented so it's clear to a user. Though passing args down the stream as a dict might bring other issue when we'll have to merge 2 or more dicts - so back to the original problem. We can take any approach but it should be consistent across all API. I'd suggest to use **dict(iterable, **kwargs) to pass caller kwargs downstream
Basically always pass down caller args if they are not overwritten by a callee. That would make kwargs usage safe and consistent, can be documented, just few changes and no additional API required |
I agree with those suggestions. I think the clear docs on any kwargs that might be popped and reassigned is a reasonable trade-off. I also like the **dict(kwargs...) pattern proposed and naming the kwargs after their downstream consumer target. Would it be reasonable to warn if we swallowed a kwargs with a replacement? Or do you think that's be unnecessary work? |
This problem exists if you use I think the solution is to check just before calling the downstream function if there is a conflict and then either raise an exception or use the value from the "passed through" dictionary. If both I would define My thinking behind introducing an explicit argument to pass the keyword arguments ( I don't see a downside to using an explicit argument as all the problems of merging/conflict resolution are the same. It is also what most other Python code does that I know of (for example multiprocessing uses |
Although I like the seamlessness of using kwargs to pass additional args, I think that have an explicit named parameter for passing kwargs is a much better approach from an API design perspective. It seems like we mostly agree on the following fundamentals of the implementation:
|
Sorry I'm just catching up on this discussion. I need a bit of time to wrap my head around what we are trying to achieve. It's not clear to me that we are not complicating things with these approaches. |
Do we have consensus on changing to I generally like writing |
In #351 it was raised that the manner in which we pass kwargs hasn't been well defined. We have several places where we pass everything downstream with **kwargs. But we don't control for duplicate names, especially as we're making API improvements.
Having kwarg passing is very useful from plugins we didn't write to be able to control their execution easily, and I'd prefer we keep a mechanism for passing parameters and data to any registered handler methods to support use cases we haven't thought or which are specific to a particular use case.
Off the top of mind I can think of two simple ways to address the name overlap issue.
**
splat patternOne of us will need to implement the solution we land on, likely before the next release. I assigned maintainers involved in the original discussion for now.
The text was updated successfully, but these errors were encountered: