-
Notifications
You must be signed in to change notification settings - Fork 279
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
Add default arguments to delegation #175
Comments
@kessido can you provide an example of why this would be useful? Why do you need to add additional args other than what is provided in delegates or what is in the function that is being delegated to? It would be helpful to understand the use case if you have one in mind! (it sounds like you might from the code above, but I don't want to guess). |
Apologies for closing in error! |
Sorry quite occupied right now.
instead, more succinctly:
|
For more informative answer, I find that many times there is many repetitions in code with delegations where the default of some variable is changed in the specific function. Imo adding the overridden default in the definition, like:
I think that for code readability adding it as a attribute is ok (in the top of the function), and the code itself become more clean with less places to mess up the overridden defaults. |
I need a similar behavior. I think a simpler example would be helpful. If you do: class A():
def __init__(a=1,b=2):pass
@delegates(A)
def some_fn(**kwargs): print(kwargs)
some_fn()
>>> {} When I would expect: class A():
def __init__(a=1,b=2):pass
@delegates(A)
def some_fn(**kwargs): print(kwargs)
some_fn()
>>> {a:1,b:2} Why do I want to do this? A more complicated example if when I want to use a call_parse cli function to initialize a class: class A():
def __init__(
a:int=1, # I want the docments for the parameter `a` to show up for `run_a` as well.
b:int=2, # I want the docments for the parameter `b` to show up for `run_a` as well.
log:str='info' # I want the docments for the parameter `log` to show up for `run_a` as well.
):pass
@call_parse
@delegates(A)
def run_a(**kwargs):
logging.basicConfig(**default_logging())
_logger.setLevel(kwargs['log'])
a=A(**kwargs)
with a: a.loop() Its pretty annoying to need to type the description and type hints twice to be able to do this, and delegates almost gets me there. |
I have a feeling some or all of this was recently added by @muellerzr ... |
Yes. If you use delegates any docment-defined definitions it will get picked up and shown with show_doc @josiahls (Unsure about the print(**kwargs), but at the minimum documentation trickles) |
Scenario:
You have function a, e.g:
def cnn(c_in, c_mid, c_out, act, bn=.., ..., blocks=CNNBlock): ...
and you want to add a specification for it:
def resnet(c_in, c_mid, c_out, act=relu, bn=..., ..., blocks=ResBlock): ... return cnn(...)
Right now as far as I understand this is the implementation:
So I'm thinking of doing this instead:
example of implementation:
What do you think?
The text was updated successfully, but these errors were encountered: