argparse support of/by argparse
lucas
lucas at bourneuf.net
Mon Jul 12 15:12:26 EDT 2021
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
More information about the Python-list
mailing list