[issue9509] argparse FileType raises ugly exception for missing file

2011-01-25 Thread SilentGhost

SilentGhost ghost@gmail.com added the comment:

Steven, I'm wondering why do you raise ArgumentTypeError there? From reading 
doc strings of the relevant errors, it seems obvious to me that it should be 
ArgumentError. Argument is being used there, there's no conversion occurring 
anywhere.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-25 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

It's an ArgumentTypeError because that's what you're supposed to raise inside 
type functions:

http://docs.python.org/dev/library/argparse.html#type

(Note that argparse.FileType.__call__ is what will be called when we pass 
type=argparse.FileType(...) to add_argument.)

The current docstring for ArgumentTypeError is correct - it says it's An error 
from trying to convert a command line string to a type and we're converting a 
file path (string) into a file object.  But I certainly wouldn't complain if 
someone wanted to make the wording there clearer. Basically the rule is:

* Use ArgumentTypeError when you're defining a type= function
* Use ArgumentError otherwise

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-24 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

No, it sounds fine then.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-24 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

Fixed in r88169 and r88171. Thanks everyone for your help! I'll be keeping my 
eye on the buildbots for a bit to make sure everything stays green.

--
assignee:  - bethard
resolution:  - fixed
stage: patch review - committed/rejected
status: languishing - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-24 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Oops, I missed that while reading the patch: It introduces a translatable 
string which may cause i18n issues (discussed in #10528).  I can propose a 
patch this week if no-one beats me to it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-23 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

Georg, is this something we can patch for rc2? It's a bug - errors encountered 
by argparse-internal code should be translated into command line errors, and 
they currently aren't for read-only files.

For what it's worth, the tests fail when the new test_argparse test is added, 
and pass when the patch is applied, and I have personally reviewed the code and 
run the entire test suite on OS X and everything still passes.

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-23 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

This would be acceptable to patch; I wonder whether to swallow the exception 
text of IOError though.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-23 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

Good point. Here's the updated patch that reports the IOError as well. All 
tests pass. I'll apply in a bit if I don't hear otherwise.

--
Added file: http://bugs.python.org/file20491/argparse.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-23 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Library patch looks good.

Tests: Does the create_readonly_file helper work on all platforms, esp. 
Windows?  Maybe it's better to create a different error situation?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-23 Thread SilentGhost

SilentGhost ghost@gmail.com added the comment:

I've tested this on windows. It passed all test.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-23 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

The docs for os.chmod claim:

Availability: Unix, Windows.
Although Windows supports chmod(), you can only set the file's read-only flag 
with it (via the stat.S_IWRITE and stat.S_IREAD constants or a corresponding 
integer value). All other bits are ignored.

So at least according to the current docs, we should be okay calling 
`os.chmod(file_path, stat.S_IREAD)` on Unix and Windows (and of course OS X 
too). Is that enough or did you have other platforms in mind?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread SilentGhost

Changes by SilentGhost ghost@gmail.com:


--
status: open - languishing

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

SilentGhost, can you remove old files from the report (or tell which ones I 
should remove if you can’t do it) and make one patch with code and test changes 
that apply cleanly to current py3k?  That would make a final review by Steven 
easier.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread SilentGhost

SilentGhost ghost@gmail.com added the comment:

Here is the single patch. All tests pass.

--
Added file: http://bugs.python.org/file20456/argparse.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread SilentGhost

Changes by SilentGhost ghost@gmail.com:


Removed file: http://bugs.python.org/file19827/test_argparse.py.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread SilentGhost

Changes by SilentGhost ghost@gmail.com:


Removed file: http://bugs.python.org/file19805/argparse.py.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread akira

akira 4kir4...@gmail.com added the comment:

no such file or directory '%s' is misleading if you are trying to open a 
readonly file for writing.

The message might be replace by: can't open '%s'

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread SilentGhost

Changes by SilentGhost ghost@gmail.com:


Added file: http://bugs.python.org/file20458/argparse.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2011-01-19 Thread SilentGhost

Changes by SilentGhost ghost@gmail.com:


Removed file: http://bugs.python.org/file20456/argparse.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-27 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

Tried to comment in Rietveld but it didn't work for some reason. Anyway, I 
think the argparse.py patch isn't good - changing the type error message to 
'invalid %s value: %r details: %s' will change the behavior of a bunch of 
programs, and it's not clearly for the better. Instead, you should raise an 
ArgumentTypeError instead of a ValueError, and give it whatever message you 
want there. That is, let's keep this patch local to the FileType, and not touch 
the rest of argparse.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-27 Thread SilentGhost

SilentGhost michael.mischurow+...@gmail.com added the comment:

Steven, I'm not sure why you're insisting on ArgumentTypeError, when it should 
be ArgumentError. The file name is not coerced into a different file type, but 
rather the error occurs when trying to use parameter passed.

In any way, my patch is still available. Do you not like something about it?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-27 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

Sorry, I was looking at the akira patch with the same date, where I was mainly 
worried about the modification of the except (TypeError, ValueError): block. 
Your patch doesn't do that, and looks fine.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-26 Thread SilentGhost

Changes by SilentGhost michael.mischurow+...@gmail.com:


Removed file: http://bugs.python.org/file19815/test_argparse.py.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-26 Thread SilentGhost

SilentGhost michael.mischurow+...@gmail.com added the comment:

On windows proposed changes to Lib/test/test_argparse.py cause it to enter an 
infinite loop in TempDirMixin.tearDown method.

As it seemed exclusively Windows issue, this new patch replaces while loop with 
the ignore_errors parameter for shutil.rmtree.

Now all test pass.

--
Added file: http://bugs.python.org/file19827/test_argparse.py.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-25 Thread SilentGhost

SilentGhost michael.mischurow+...@gmail.com added the comment:

Ammended akira's patch for Lib/test/test_argparse.py to include suggested in 
review changes: with statement, import statement

--
Added file: http://bugs.python.org/file19815/test_argparse.py.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-24 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

I'm not sure about the patch - this will convert *all* IOErrors into command 
line error messages, while we should really only be converting the ones raised 
by FileType. Instead, the try/except should be in FileType.__call__, and you 
should raise an ArgumentTypeError there.

The test looks fine.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-24 Thread SilentGhost

SilentGhost michael.mischurow+...@gmail.com added the comment:

Attached patch with the try-except clause as suggested by Steven, Doug's 
example now produces the following output:

$ ./python argparse_filetype_error.py
usage: argparse_filetype_error.py [-h] [-i I]
argparse_filetype_error.py: error: no such file or directory 
'file-does-not-exist.txt'

I have digressed and fixed an issue with _bufsize 0. I thought it would be just 
natural to default to -1 which is default buffering size for a simple open call 
anyway. It also makes for a cleaner try-except clause. All tests pass, 
including akira's.

--
nosy: +SilentGhost
Added file: http://bugs.python.org/file19805/argparse.py.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-24 Thread akira

akira 4kir4...@gmail.com added the comment:

I've added tests for readonly files. SilentGhost's patch doesn't handle this 
case.

--
Added file: http://bugs.python.org/file19806/test_argparse.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-24 Thread akira

akira 4kir4...@gmail.com added the comment:

Attached patch for argparse.py (argparse.diff -- without tests, see tests in 
test_argparse.diff) where ValueError is raises in FileType.__call__ and 
additional details printed on ArgumentError

--
Added file: http://bugs.python.org/file19807/argparse.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-24 Thread akira

akira 4kir4...@gmail.com added the comment:

updated patch on http://codereview.appspot.com/3251041/

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-21 Thread Tarsis Azevedo

Tarsis Azevedo tarsis.azev...@gmail.com added the comment:

Hi Doug,

I catched the IOError exception and used the error function of ArgumentParser 
class to return a beautful error message.

--
keywords: +patch
nosy: +Tarsis.Azevedo
Added file: http://bugs.python.org/file19749/issue9509.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-21 Thread Doug Hellmann

Doug Hellmann doug.hellm...@gmail.com added the comment:

Hi, Tarsis,

That patch looks good to me.

Thanks!
Doug

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-21 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Looks good to me too.  Steven, does this require a test?

--
nosy: +eric.araujo
stage:  - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-21 Thread Doug Hellmann

Doug Hellmann doug.hellm...@gmail.com added the comment:

Oh, yeah, a test is a good idea.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-21 Thread akira

akira 4kir4...@gmail.com added the comment:

Simplified the patch and added test for a non-existent file in issue9509.patch

The test `py3k/python -m test.regrtest test_argparse` fails without the patch 
and succeeds with it.

The docs in Doc/library/argparse.rst and Lib/argparse.py  don't need to be 
changed (neither mention IOError and it is a buf fix).

Misc/NEWS and Misc/ACKS don't need to be changed (?).

I've uploaded the patch to Rietveld http://codereview.appspot.com/3251041/

--
nosy: +akira
type:  - behavior
Added file: http://bugs.python.org/file19758/issue9509.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-11-21 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

I don’t know enough of the test_argparse magic to assess the new test, but 
Stephan, the author and maintainer of argparse, will certainly comment when he 
gets some time.  Thanks for the patch!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-09-07 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
nosy: +bethard

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-08-05 Thread Doug Hellmann

Changes by Doug Hellmann doug.hellm...@gmail.com:


--
keywords: +easy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-08-04 Thread Doug Hellmann

New submission from Doug Hellmann doug.hellm...@gmail.com:

Most of the argparse type converters handle exceptions with a single line error 
message explaining the problem.  For example, if an argument -i is declared as 
an int, but the value given ('a') cannot be converted to an int, the message is 
something like argument -i: invalid int value: 'a'.  

On the other hand, FileType raises an IOError, which isn't being caught and 
converted to the simpler error message. Instead, a full traceback is printed.  
To be consistent, the IOError should be trapped and a single error message 
printed.

--
components: Library (Lib)
files: argparse_filetype_error.py
messages: 112798
nosy: doughellmann
priority: normal
severity: normal
status: open
title: argparse FileType raises ugly exception for missing file
versions: Python 2.7, Python 3.2
Added file: http://bugs.python.org/file18380/argparse_filetype_error.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9509] argparse FileType raises ugly exception for missing file

2010-08-04 Thread Doug Hellmann

Changes by Doug Hellmann doug.hellm...@gmail.com:


Added file: http://bugs.python.org/file18381/argparse_int_error.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9509
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com