python-fire icon indicating copy to clipboard operation
python-fire copied to clipboard

[FEATURE REQUEST] typed arguments

Open Nov1kov opened this issue 5 years ago • 3 comments

If I write a typed variable argument, I am expecting an argument of a specific type. Example:

import fire

def test(some_str: str):
    print(some_str)

if __name__ == "__main__":
    fire.Fire()

Real result:

python test.py test 7.30
7.3

Expected Result:

python test.py test 7.30
7.30

So this feature will not break argument parsing. The typed argument should be enough to detect the real type.

Nov1kov avatar Dec 04 '20 13:12 Nov1kov

Hello @Nov1kov, I was wondering if you want to add typed args to the whole codebase or there are some priority files? either way, I would like to take this issue

UrielMaD avatar Dec 17 '20 07:12 UrielMaD

@UrielMaD Hello! Sorry for the late answer. I don't inspect the codebase yet. I'll be happy If you want to make this feature! 👍

I guess the feature is quite huge. We should define:

  1. Unexpected types (e.g. def method(arg: MyCustomObject):
  2. raise Exceptions for unexpected types.

Nov1kov avatar Dec 23 '20 06:12 Nov1kov

@dbieber, do you think this behavior (casting command line argument values based on the function signature) is a good idea? If so, I'd like to work with you to define the feature and push through one of #350 or #320 or a variation of those.

indigoviolet avatar Sep 19 '22 23:09 indigoviolet