Is there a way to have Python static analyzers (e.g. in PyCharm, other IDEs) pick up on Typehints on argparse.Namespace
objects? Example:
parse
Typed argument parser was made for exactly this purpose. It wraps argparse
. Your example is implemented as:
from tap import Tap
class ArgumentParser(Tap):
somearg: str
parsed = ArgumentParser().parse_args(['--somearg', 'someval'])
the_arg = parsed.somearg
Here's a picture of it in action.
It's on PyPI and can be installed with: pip install typed-argument-parser
Full disclosure: I'm one of the creators of this library.