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

[suggestion] tapify(...) should support classes/objects by producing subargument parsers #101

Open
baodrate opened this issue Mar 7, 2023 · 1 comment · May be fixed by #140
Open

[suggestion] tapify(...) should support classes/objects by producing subargument parsers #101

baodrate opened this issue Mar 7, 2023 · 1 comment · May be fixed by #140
Labels
enhancement New feature or request

Comments

@baodrate
Copy link
Contributor

baodrate commented Mar 7, 2023

With #96, tapify() was introduced, which automagically produces and executes the appropriate argparse code based on the type annotations of the passed function:

from tap import tapify

def add(num_1: float, num_2: float) -> float:
    print(f'The sum of {num_1} and {num_2} is {num_1 + num_2}.')

if __name__ == '__main__':
    tapify(add)

similar to python-fire, tapify should support objects and/or classes, such that subparsers are created for each method. e.g.:

class Calculator(object):
  def __init__(self, offset: int = 1):
      self._offset = offset

  def add(self, x: int, y: int):
    print(x + y + self._offset)

  def multiply(self, x: int, y: int):
    print(x * y + self._offset)

if __name__ == '__main__':
  tapify(Calculator, offset=1)

Should produce a main parser with one optional --offset argument and two subparsers (add and multiply) with the appropriate options.

@swansonk14 swansonk14 added the enhancement New feature or request label Jun 25, 2023
@swansonk14
Copy link
Owner

Hi @qubidt,

This seems like a great extension of tapify! We hope to tackle this soon but would appreciate any PRs.

Thanks,
Jesse and Kyle

@kddubey kddubey linked a pull request Jun 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants