[New-bugs-announce] [issue38843] Document argparse behaviour when custom namespace object already has the field set
Ivan Kurnosov
report at bugs.python.org
Mon Nov 18 21:23:43 EST 2019
New submission from Ivan Kurnosov <zerkms at zerkms.com>:
At this moment it's impossible to explain the behaviour of this script using documentation.
Given it was explicitly coded to behave like that - it should be somehow noted in the documentation, that as long as a `CliArgs.foo` field has a default value set already - it won't be overwritten with a default argparse argument value.
```
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'
```
----------
assignee: docs at python
components: Documentation
messages: 356939
nosy: docs at python, zerkms
priority: normal
severity: normal
status: open
title: Document argparse behaviour when custom namespace object already has the field set
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38843>
_______________________________________
More information about the New-bugs-announce
mailing list