Issue 11175: allow argparse FileType to accept encoding and errors arguments (original) (raw)

Created on 2011-02-10 15:47 by bethard, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
filetype11175.patch lum,2012-10-23 12:06 patch review
filetype11175.patch lum,2012-10-26 15:11 review
filetype11175.patch lum,2012-11-27 15:15 review
filetype11175.patch lum,2012-12-03 07:43 review
Messages (18)
msg128301 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2011-02-10 15:47
Suggestion from a personal email: Allow FileType to accept encoding and errors arguments and pass these as keyword arguments to codecs.open() instead of open().
msg128310 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-02-10 17:02
The encoding and errors arguments are probably useful, but why would you use the codecs module?
msg128318 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2011-02-10 17:35
Probably because the suggestion came from someone thinking about both Python 2 and 3. But given that this feature request can only target Python 3.3, you're absolutely right that there's no need to go through the codecs module.
msg173599 - (view) Author: Lucas Maystre (lum) * Date: 2012-10-23 12:06
Here's an attempt at implementing this (my first contribution). Some notes: - I tried to keep `__repr__()` backwards compatible. It would have been easier to inherit from `_AttributeHolder`, but maybe this might break some things... - I added some test cases for `__repr__()`, but that's it. I don't think there's any other sensible test to do, as we're really just passing stuff to `open()` - not sure about the style, especially line breaks...
msg173603 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-10-23 12:21
Lucas: You only added tests for the repr, you should probably test the actual new functionality, too.
msg173611 - (view) Author: Lucas Maystre (lum) * Date: 2012-10-23 13:11
OK, as discussed offline with Petri I'll put some tests to ensure that open() is called the right way (using unittest.mock.patch).
msg173851 - (view) Author: Lucas Maystre (lum) * Date: 2012-10-26 15:11
Alright, here's a version with more tests (unittest.mock is awesome!). I think it tests exactly what it should (and no more), i.e. that the arguments are correctly passed to `open`.
msg173852 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-10-26 15:15
LGTM. Let's wait for Steven's comments as he's the maintainer of argparse.
msg176403 - (view) Author: Lucas Maystre (lum) * Date: 2012-11-26 08:18
Is there something I can do something to move this forward?
msg176404 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-11-26 09:00
Since Steven is not responding, I think I can commit it at some point. Thanks for the remainder :)
msg176414 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-11-26 14:12
The patch needs documentation, though, right? http://docs.python.org/dev/library/argparse.html#filetype-objects
msg176464 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-11-27 06:42
Right, good point. Lucas, could you fix the documentation too?
msg176472 - (view) Author: Lucas Maystre (lum) * Date: 2012-11-27 12:21
OK, I'll give it a try.
msg176479 - (view) Author: Lucas Maystre (lum) * Date: 2012-11-27 15:15
Added some documentation for the patch. Let me know what you think.
msg176829 - (view) Author: Lucas Maystre (lum) * Date: 2012-12-03 07:43
As per Ezio's comment, changed "l1" to "utf-8" in the example of the doc.
msg177561 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-12-15 20:44
New changeset d5a0698a8354 by Petri Lehtinen in branch 'default': #11175: argparse.FileType now accepts encoding and errors arguments. http://hg.python.org/cpython/rev/d5a0698a8354
msg177562 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-12-15 20:46
Committed, thanks for the patch! I made little tweaks before committing: - changed l1 to UTF-8 in the example (guess you mis-uploaded the latest version) - changed the argument to 'replace' in test_r_1_replace - fixed 3-space indentation to 4-space indentation in test_open_args
msg177638 - (view) Author: Lucas Maystre (lum) * Date: 2012-12-17 07:41
Sorry for the little glitches you had to fix, I wonder why I didn't catch them. Anyways, thanks Petri!
History
Date User Action Args
2022-04-11 14:57:12 admin set github: 55384
2012-12-17 07:41:25 lum set messages: +
2012-12-15 20:46:16 petri.lehtinen set status: open -> closedresolution: fixedmessages: + stage: commit review -> resolved
2012-12-15 20:44:02 python-dev set nosy: + python-devmessages: +
2012-12-03 07:43:05 lum set files: + filetype11175.patchmessages: +
2012-11-27 15:15:34 lum set files: + filetype11175.patchmessages: +
2012-11-27 12:21:30 lum set messages: +
2012-11-27 06:42:09 petri.lehtinen set messages: +
2012-11-26 14:12:13 chris.jerdonek set nosy: + chris.jerdonekmessages: +
2012-11-26 09:00:36 petri.lehtinen set assignee: petri.lehtinenmessages: +
2012-11-26 08🔞22 lum set messages: +
2012-10-26 15:28:46 berker.peksag set nosy: - berker.peksag
2012-10-26 15:15:30 petri.lehtinen set keywords: + needs reviewmessages: + stage: patch review -> commit review
2012-10-26 15:11:45 lum set files: + filetype11175.patchmessages: +
2012-10-24 21:25:27 ezio.melotti set nosy: + ezio.melotti
2012-10-23 13:11:50 lum set messages: +
2012-10-23 12:21:48 petri.lehtinen set nosy: + petri.lehtinenmessages: + stage: needs patch -> patch review
2012-10-23 12:06:15 lum set files: + filetype11175.patchnosy: + lummessages: + keywords: + patch
2012-10-18 16:04:58 petri.lehtinen set versions: + Python 3.4, - Python 3.3
2011-12-12 16:44:56 berker.peksag set nosy: + berker.peksag
2011-07-19 14:56:09 eric.araujo set keywords: + easynosy: + eric.araujo
2011-02-10 17:35:23 bethard set messages: +
2011-02-10 17:02:12 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2011-02-10 15:47:13 bethard create