[issue38843] Document argparse behaviour when custom namespace object already has the field set

2019-11-18 Thread Ivan Kurnosov


New submission from Ivan Kurnosov :

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@python
components: Documentation
messages: 356939
nosy: docs@python, zerkms
priority: normal
severity: normal
status: open
title: Document argparse behaviour when custom namespace object already has the 
field set

___
Python tracker 
<https://bugs.python.org/issue38843>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38843] Document argparse behaviour when custom namespace object already has the field set

2019-11-18 Thread Ivan Kurnosov


Ivan Kurnosov  added the comment:

> I have not seen many questions about the use of a preexisting namespace 
> object (here or on StackOverflow)

as typing was added to the language natively - it should become more and more 
frequently used.

I personally see no reason anymore to NOT use a custom namespace: typed 
arguments object is x100 times better than untyped one.

--

___
Python tracker 
<https://bugs.python.org/issue38843>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com