-
Notifications
You must be signed in to change notification settings - Fork 43
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
Introduce decorator-style API #3
Comments
Decorator is a cool thing, should have batch/name arguments. As I understand the implementation, the following should work as well. I think it will be a good thing to work around with first argument of import functools
NotDefined = object()
def wrap(func=NotDefined, arg=1, **kwargs):
if func is NotDefined:
args = locals().copy()
args.pop('func')
args.pop('kwargs')
args.update(kwargs)
return functools.partial(wrap, **args)
# or your code below
def wrapped(**kwargs1):
if arg == 1:
print('hi')
else:
print('bye')
kw = kwargs.copy()
kw.update(kwargs1)
return func(**kw)
return wrapped
def fn1(a=1, b=2):
print('a =', a)
print('b =', b)
@wrap
def fn2(a=1, b=2):
print('a =', a)
print('b =', b)
@wrap(arg=2)
def fn3(a=1, b=2):
print('a =', a)
print('b =', b)
fn4 = wrap(fn1, arg=2, a=3)
fn1()
fn2()
fn3()
fn4()
-------------
a = 1
b = 2
hi
a = 1
b = 2
bye
a = 1
b = 2
bye
a = 3
b = 2 |
you can use https://github.com/ferrine/biwrap, available at pypi |
Nice suggestion! I will take a look at this soon, thanks. |
I have been working on this these days, please see #7 (in progress).
/cc @ferrine Do you want to take a look or review it? |
I believe this API is good enough, will be released as v0.3. https://github.com/wookayin/tensorflow-plot/blob/master/examples/showcases.ipynb |
Oh, I was missiing notifications for a long time, is review still needed? |
If you want to kindly give some suggestions, it would be greatly appreciated of course. |
Decorators are pretty?
For example (name is undecided), we can simply define a decorated "op builder" function:
Instead of:
The text was updated successfully, but these errors were encountered: