Attributes annotated with int are converted to type=int in ArgumentParser

import attr

from clime import clime


@attr.s(auto_attribs=True)
class Dude:
    age_in_years: int

    def confess_age(self):
        print(f"I am {self.age_in_years} years old.")


def main():
    clime(Dude).confess_age()


if __name__ == "__main__":
    main()
Check it:

$ python docs_src/integers_floats_and_other_simple_classes/tutorial_001.py

usage: tutorial_001.py [-h] age_in_years

positional arguments:
  age_in_years  type: <int>

optional arguments:
  -h, --help    show this help message and exit

Cool!

  • age_in_years is annotated withint
  • CliMe takes converts it into an integer Try it!
$ python docs_src/integers_floats_and_other_simple_classes/tutorial_001.py 12
I am 12 years old.

Non-integers will be caught by ArgumentParser

$ python docs_src/integers_floats_and_other_simple_classes/tutorial_001.py hi
usage: tutorial_001.py [-h] age_in_years
tutorial_001.py: error: argument age_in_years: invalid int value: 'hi'
$ python docs_src/integers_floats_and_other_simple_classes/tutorial_001.py 12.1
usage: tutorial_001.py [-h] age_in_years
tutorial_001.py: error: argument age_in_years: invalid int value: '12.1'

That's it.