Hello everyone,

Let us consider this patch of code:

    import argparse

    def parse_cli() -> argparse.Namespace:
        parser = argparse.ArgumentParser()
        parser.add_argument('n', type=int)
        return parser.parse_args()

    args = parse_cli()
    print(args.n + ' ')  # type error

Running CPython on it will raise a TypeError, and running Mypy on it will indicate that no issues were found.

I was wondering if there is any way for me to have mypy detecting the args.n type, based on the type keyword of the parser.add_argument function ?

It appears that some type annotations were added to tierce party modules, provided by mypy itself. Is there a technical issue preventing such work to be made for argparse (or other CLI ; i didn't find anything for others either)

Thank you for reading,
--lucas
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to