How can I use instance methods as commands in Argh?

4 views
Skip to first unread message

Zach Abresch

unread,
Apr 1, 2020, 12:48:12 PM4/1/20
to argh-users
I have a class that bundles a bunch of related functionality. I'd like to make an instance's methods available as commands with Argh. I used a snippet to extract a list of callable, non-dunder methods from my instance and then tried passing those to `.add_commands()` but, when running the app, I get the following error:

`AttributeError: 'str' object has no attribute '__name__'`

Is this possible? I've been scouring the docs and provided examples but haven't found anything that addresses my use case. Thanks for any help anyone can provide.

Zach Abresch

unread,
Apr 1, 2020, 12:49:14 PM4/1/20
to argh-users
Here's the comprehension I'm using to get the instance methods:

object_methods = [
       method_name
       for method_name in dir(git)
       if callable(getattr(git, method_name))
       and not (method_name.startswith("__") and method_name.endswith("__"))
   ]


Reply all
Reply to author
Forward
0 new messages