I have noticed that the default argument value is not set when the custom namespace object is used:
import argparse
class CliArgs(object):
foo: str = 'not touched'
parser = argparse.ArgumentParser()
parser.add_argument('--foo', default='bar')
args = CliArgs()
parser.parse_args(namespace=args)
print(args.foo) # 'not touched'
print(parser.parse_args()) # 'bar'
ideone: https://ideone.com/7P7VxI
I expected bar to be set in both cases.
Is it expected? I cannot see it in the documentation though.
And if it's expected, is there then really no way to implement that other than using some custom action?
UPD: I reported it as a documentation bug https://bugs.python.org/issue38843
add_argumentwon't be processed at all.not touchedthere is purely for that reason