This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年04月12日 19:56 by Paolo.Elvati, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| fopatch | Mike.Meyer, 2012年05月03日 01:16 | |||
| Messages (6) | |||
|---|---|---|---|
| msg133598 - (view) | Author: Paolo Elvati (Paolo.Elvati) | Date: 2011年04月12日 19:56 | |
Hi,
when a default is specified for a file argument that is open with writing permission (FileType('w')), the default file is always created even if the argument is specified in the command line.
For example he code:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"-o",
default = 'fake',
dest = 'OutputFile',
type = argparse.FileType('w')
)
args = parser.parse_args()
will create the empty file "fake" even if the -o option is given.
The value inside the code of args.Outputfile is not affected.
Paolo
|
|||
| msg134559 - (view) | Author: Manveru (manveru) | Date: 2011年04月27日 12:44 | |
I have the same issue with default here with 2.7. Fortunately I have my own type function so I can prevent is by changing my internal state. This is however only a workaround for real bug in the argparse. |
|||
| msg134956 - (view) | Author: Stefan Pfeiffer (Stefan.Pfeiffer) | Date: 2011年05月02日 09:10 | |
Happens in 3.2, too... Would be nice to see that fixed. Stefan |
|||
| msg149546 - (view) | Author: Steven Bethard (bethard) * (Python committer) | Date: 2011年12月15日 12:38 | |
I think Issue 12776, which delays type conversions on defaults, should solve this problem, right? If you agree, could you add your code here as a test case to that issue and mark this as duplicate? |
|||
| msg159828 - (view) | Author: Mike Meyer (Mike.Meyer) | Date: 2012年05月03日 01:16 | |
Steven - 12776 indeed fixes this issue. I applied the patch from it to a build of todays checkout, verified that my simple test script worked, then wrote some test cases for test_argparse. I've uploaded the patch for that test to both issues. I can't close this as a duplicate, though. |
|||
| msg169609 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年09月01日 03:16 | |
New changeset 1b614921aefa by R David Murray in branch '3.2': #12776,#11839: call argparse type function only once. http://hg.python.org/cpython/rev/1b614921aefa New changeset 74f6d87cd471 by R David Murray in branch 'default': Merge #12776,#11839: call argparse type function only once. http://hg.python.org/cpython/rev/74f6d87cd471 New changeset 62b5667ef2f4 by R David Murray in branch '2.7': #12776,#11839: call argparse type function only once. http://hg.python.org/cpython/rev/62b5667ef2f4 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:16 | admin | set | github: 56048 |
| 2012年09月01日 03:16:48 | python-dev | set | nosy:
+ python-dev messages: + msg169609 |
| 2012年05月03日 09:36:44 | Paolo.Elvati | set | status: open -> closed |
| 2012年05月03日 09:36:13 | Paolo.Elvati | set | status: closed -> open |
| 2012年05月03日 09:34:01 | Paolo.Elvati | set | status: open -> closed resolution: duplicate |
| 2012年05月03日 01:16:46 | Mike.Meyer | set | files:
+ fopatch nosy: + Mike.Meyer messages: + msg159828 |
| 2011年12月15日 12:38:19 | bethard | set | messages: + msg149546 |
| 2011年05月02日 09:10:18 | Stefan.Pfeiffer | set | nosy:
+ Stefan.Pfeiffer messages: + msg134956 |
| 2011年04月27日 12:44:00 | manveru | set | nosy:
+ manveru messages: + msg134559 versions: + Python 2.7 |
| 2011年04月12日 19:56:29 | Paolo.Elvati | create | |