Skip to content
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

Proxy definitions #51

Open
neithere opened this issue Jan 2, 2014 · 0 comments
Open

Proxy definitions #51

neithere opened this issue Jan 2, 2014 · 0 comments

Comments

@neithere
Copy link
Owner

neithere commented Jan 2, 2014

Let's say we want to add a command to the parser with slightly different configuration:

class Foo:
    def meth(self):
        pass

foo = Foo()

command = argh.named('another-name')(foo.meth)    # WRONG!

dispatch_commands([command])

This is wrong because:

  1. the code won't work because accessing the method's function is not the same as accessing the method (extra checks are needed);
  2. the decorator (re)sets an object's attribute. If we only need to set a value right here, we should not touch the object itself; a proxy/wrapper should be applied instead.

For example (syntax to be improved):

@named('one')
def foo():
    pass

bar = proxy_named(foo, 'one')

assert foo.argh_name == 'one'
assert bar.argh_name == 'two'

The named decorator may be used for this purpose, too; it should be less transparent in that case.

neithere added a commit that referenced this issue Jan 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant