[issue10461] Use with statement throughout the docs

2011-03-12 Thread Éric Araujo
Éric Araujo added the comment: Thanks for the catch! I was so used to the idiom where opening the file doesn’t fail but you protect the read or write that I didn’t think about the issue here. -- stage: commit review -> committed/rejected status: open -> closed __

[issue10461] Use with statement throughout the docs

2011-03-12 Thread Roundup Robot
Roundup Robot added the comment: New changeset cebaf1bdaf78 by Éric Araujo in branch 'default': Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow-up). http://hg.python.org/cpython/rev/cebaf1bdaf78 -- status: pending -> open __

[issue10461] Use with statement throughout the docs

2011-03-11 Thread SilentGhost
SilentGhost added the comment: Éric, I'm not sure about the first atexit.rst hunk. I thought the purpose of that code was to except IOError when no file is found. I'm not entirely sure why in the simplest case infile.read() would raise IOError. I'd think that eli's patch (file19667) would sui

[issue10461] Use with statement throughout the docs

2011-03-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset c3d28c84a372 by Éric Araujo in branch 'default': Use with statement where it improves the documentation (closes #10461) http://hg.python.org/cpython/rev/c3d28c84a372 -- nosy: +python-dev resolution: accepted -> fixed status: open -> closed

[issue10461] Use with statement throughout the docs

2011-03-11 Thread Éric Araujo
Éric Araujo added the comment: > Perhaps something should also be added to the doc style guide (along > with using 'attributes' instead of 'members'). Terry, could you open another report for that, or maybe just commit the change directly? -- ___ P

[issue10461] Use with statement throughout the docs

2010-12-20 Thread Vinay Sajip
Vinay Sajip added the comment: I've already made the change, Terry, just holding off committing it because Georg has frozen the py3k branch until 3.2b2 is released. There are a few other changes I'm making, will commit these soon after 3.2b2 is released. -- _

[issue10461] Use with statement throughout the docs

2010-12-19 Thread Terry J. Reedy
Terry J. Reedy added the comment: Vinay, you should look at the logging-cookbook patch. -- ___ Python tracker ___ ___ Python-bugs-lis

[issue10461] Use with statement throughout the docs

2010-12-19 Thread SilentGhost
SilentGhost added the comment: following re-organization of the logging docs, I'm attaching updated patch. -- nosy: +vinay.sajip Added file: http://bugs.python.org/file20112/logging-cookbook.rst.diff ___ Python tracker

[issue10461] Use with statement throughout the docs

2010-12-19 Thread SilentGhost
Changes by SilentGhost : Removed file: http://bugs.python.org/file19671/logging.rst.diff ___ Python tracker ___ ___ Python-bugs-list mailing l

[issue10461] Use with statement throughout the docs

2010-11-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I’m not 100% sure I should change 'r' to 'rb' in logging: > It’s unrelated to with, and the rest of the file > has not been checked for similar errors. Good catch. This should only be a with-statement transformation. I caught other accidental semantic

[issue10461] Use with statement throughout the docs

2010-11-21 Thread Eli Bendersky
Eli Bendersky added the comment: Éric, Yes, in a consequent patch I fixed this - kept the formatted code indented at 3 spaces, while adhering to PEP-8 internally. If there's anything else, let me know. -- ___ Python tracker

[issue10461] Use with statement throughout the docs

2010-11-21 Thread Éric Araujo
Éric Araujo added the comment: Raymond: I made a single diff for easier review. I’m not 100% sure I should change 'r' to 'rb' in logging: It’s unrelated to with, and the rest of the file has not been checked for similar errors. I prefer to do commits that don’t mix things. Eli: > which whi

[issue10461] Use with statement throughout the docs

2010-11-21 Thread Éric Araujo
Changes by Éric Araujo : Removed file: http://bugs.python.org/file19696/unnamed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsub

[issue10461] Use with statement throughout the docs

2010-11-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: Éric, please apply most of these. In the atexit patch, the first change is wrong. Change it to a try/except/finally or skip it altogether. In the collections patch, only include the change for the tail example; the other two should remain unchanged. Ski

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Eli Bendersky added the comment: On Sat, Nov 20, 2010 at 20:44, Éric Araujo wrote: > > Éric Araujo added the comment: > > Eli, SilentGhost: Please open other bug reports for doc errors like the > struct one in stdlib2 or the r/rb one. > > SilentGhost: with statement used with open *is* abou

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Éric Araujo
Éric Araujo added the comment: Eli, SilentGhost: Please open other bug reports for doc errors like the struct one in stdlib2 or the r/rb one. SilentGhost: with statement used with open *is* about file reading :) Raymond: I agree about try/finally. I agree with Alexander about collections.rs

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Alexander Belopolsky
Changes by Alexander Belopolsky : -- Removed message: http://bugs.python.org/msg121711 ___ Python tracker ___ ___ Python-bugs-list mai

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Alexander Belopolsky
Alexander Belopolsky added the comment: FWIW, I find the "with" variant much easier to read than >>> words = re.findall('\w+', open('hamlet.txt').read().lower()) Too many operations in one line. It would be even better with >>> words = re.findall('\w+', hamlet_text.lower()) --

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: Separate note for Éric: the try/finally examples do not need to change. Those are valid python. Users need to learn both try/finally and the with-statement. -- assignee: d...@python -> rhettinger ___ Python t

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: I think the other (non collections patches) are fine. The change doesn't break up the flow of the text. -- ___ Python tracker ___

[issue10461] Use with statement throughout the docs

2010-11-20 Thread SilentGhost
SilentGhost added the comment: None of the changes are about file reading, they only about using with statement throughout. May be nofix then? -- ___ Python tracker ___ ___

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: Do not change the examples in collections.rst. That would interfere with the clarify of what is being demonstrated. For example, the hamlet.txt example is not about file reading, it about counting words. -- nosy: +rhettinger __

[issue10461] Use with statement throughout the docs

2010-11-20 Thread SilentGhost
Changes by SilentGhost : Removed file: http://bugs.python.org/file19672/logging.rst.diff ___ Python tracker ___ ___ Python-bugs-list mailing l

[issue10461] Use with statement throughout the docs

2010-11-20 Thread SilentGhost
SilentGhost added the comment: patch for Doc/library/logging.rst Also, note the the change of the mode from `'r'` to `'rb'`. `data_to_send` is further send through socket and therefore requires to be bytes. I expressed my opinion in irc, but I can repeat here that I think only the most trivi

[issue10461] Use with statement throughout the docs

2010-11-20 Thread SilentGhost
SilentGhost added the comment: patch for Doc/library/logging.rst Also, note the the change of the mode from `'r'` to `'rb'`. `data_to_send` is further send through socket and therefore requires to be bytes. I expressed my opinion in irc, but I can repeat here that I think only the most trivi

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Eli Bendersky added the comment: SilentGhost, Your patches look fine. I have a doubt re collections.rst, however - about the Python prompt. The same issue is in faq/library.rst and I didn't want to touch it because I thought that on the prompt personally I probably wouldn't use 'with' - why

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Changes by Eli Bendersky : Removed file: http://bugs.python.org/file19660/issue10461.1.diff ___ Python tracker ___ ___ Python-bugs-list mailin

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Changes by Eli Bendersky : Added file: http://bugs.python.org/file19668/issue10461.stdlib2.rst.diff ___ Python tracker ___ ___ Python-bugs-lis

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Eli Bendersky added the comment: Attaching patches for library/atexit.rst and for tutorial/stdlib2.rst -- Added file: http://bugs.python.org/file19667/issue10461.atexit.rst.diff ___ Python tracker

[issue10461] Use with statement throughout the docs

2010-11-20 Thread SilentGhost
SilentGhost added the comment: Patch for Doc/library/collections.rst -- Added file: http://bugs.python.org/file19665/collections.rst.diff ___ Python tracker ___

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Eli Bendersky added the comment: I'm trying to port the example in tutorial/stdlib2.rst, but the sample in "working with binary data record layouts" fails (before my porting to 'with'...) struct.error: unpack requires a bytes argument of length 16 -- ___

[issue10461] Use with statement throughout the docs

2010-11-20 Thread SilentGhost
SilentGhost added the comment: Here is the patch for Doc/library/difflib.rst -- Added file: http://bugs.python.org/file19664/difflib.rst.diff ___ Python tracker ___

[issue10461] Use with statement throughout the docs

2010-11-20 Thread SilentGhost
SilentGhost added the comment: Here is the patch for Docs/library/cmd.rst -- nosy: +SilentGhost Added file: http://bugs.python.org/file19663/cmd.rst.diff ___ Python tracker ___

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Eli Bendersky added the comment: Eric, which whitespace change do you refer to. I changed to 4-spaces indentation in the code sample to conform to PEP-8. Shouldn't I have? -- ___ Python tracker __

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Georg Brandl
Georg Brandl added the comment: FWIW, this doesn't belong in the style guide; it is obvious that the docs should exhibit "best practice" Python code, and using the with statement when opening resources is certainly such a best practice now. -- nosy: +georg.brandl

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Éric Araujo
Éric Araujo added the comment: Yes, that’s it. Please don’t change whitespace in your patches. -- ___ Python tracker ___ ___ Python-

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Changes by Eli Bendersky : Removed file: http://bugs.python.org/file19659/atexit.rst ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Changes by Eli Bendersky : -- keywords: +patch Added file: http://bugs.python.org/file19660/issue10461.1.diff ___ Python tracker ___ _

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Eli Bendersky added the comment: Eric, I'm attaching a provisional fix for library/atexit.rst just to be sure this is what you mean. -- Added file: http://bugs.python.org/file19659/atexit.rst ___ Python tracker _

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Éric Araujo
Éric Araujo added the comment: Certainly. Here is my secret grep: $ cd py3k/Doc $ grep -n --color=auto -d skip -I --exclude-dir .svn --exclude-dir .hg -R open\(.*\).read *.rst c-api distutils documenting extending faq howto library reference tutorial using List without false positives: faq

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Eli Bendersky
Eli Bendersky added the comment: Éric, although grepping for all such references may be tricky, could you specify the places where you did see them? I guess a few fixed places is better than none at all. -- nosy: +eli.bendersky ___ Python tracker

[issue10461] Use with statement throughout the docs

2010-11-20 Thread Éric Araujo
Éric Araujo added the comment: with also replaces open-try-do stuff-finally-close, the correct idiom for ensuring file handles are always closes in all VMs. I don’t think the doc style guide is the right place, since this is a code issue. with is advertised in http://docs.python.org/dev/tut

[issue10461] Use with statement throughout the docs

2010-11-19 Thread Ezio Melotti
Changes by Ezio Melotti : -- nosy: +ezio.melotti ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.py

[issue10461] Use with statement throughout the docs

2010-11-19 Thread Terry J. Reedy
Terry J. Reedy added the comment: +1 I have not yet had occasion to use 'with' yet, but in reading the Unicode HOWTO diff, I noticed that I liked replacing 'open,read,close' with 'with open, read' just for reading purposes since it turns 3 steps into 1 compound transaction. Perhaps something

[issue10461] Use with statement throughout the docs

2010-11-19 Thread Alexander Belopolsky
Alexander Belopolsky added the comment: +1 BTW, I've updated examples in Unicode HOWTO to use with. -- nosy: +belopolsky ___ Python tracker ___

[issue10461] Use with statement throughout the docs

2010-11-19 Thread Éric Araujo
New submission from Éric Araujo : The docs contain numerous examples that would trigger resource warnings under 3.2 (for example “open(...).read()”). They should be changed to use (and thus promote) the with statement. Not adding the “easy” keyword, since grepping for those things is not easy