(sorry if generic is the wrong word to describe this)
argparse.parse_args(namespace=MyNamespace()) returns an instance of MyNamespace, but it's annotated to always return an argparse.Namespace. This means that in order to have type-safety when accessing arguments by using a custom type-annotated class:
class Arguments:
verbose: bool
...
args = argparse.parse_args(namespace=Arguments())
you currently need to cast the return value of argparse.parse_args.
Also, the passed object doesn't actually have to be a (subclass of) argparse.Namespace – a simple subclass of object is documented to work.
(sorry if generic is the wrong word to describe this)
argparse.parse_args(namespace=MyNamespace())returns an instance ofMyNamespace, but it's annotated to always return anargparse.Namespace. This means that in order to have type-safety when accessing arguments by using a custom type-annotated class:you currently need to cast the return value of
argparse.parse_args.Also, the passed object doesn't actually have to be a (subclass of)
argparse.Namespace– a simple subclass of object is documented to work.