[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-22 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

Fixed in r70536.

--
resolution:  - fixed
status: open - closed

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-20 Thread David W. Lambert

David W. Lambert lamber...@corning.com added the comment:

My file class extends text files with seek or read through condition or 
pattern, providing an awk like pattern{action} task separation.

If I allow a pre-existing stream into my constructor (subprocess.Popen 
my favorite) I still suffer the same garbage collection problem.

class file(io.TextIOWrapper):
'add condition matching to a stream'
def __init__(self,stream_or_name):
a = stream_or_name
buffer = (a.buffer if isinstance(a, io.TextIOWrapper)
   else io.BufferedReader(io.FileIO(a, 'r')))
super().__init__(buffer)

Use this on a stream whose reference count goes to zero causes
ValueError: I/O operation on closed file.  Increasing stream's reference 
count by saving it with the object corrects it.

I appreciate your considerations.
Dave.

--

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-19 Thread Martin v. Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

 The Python 3 What's New should SCREAM that the type file is gone

I don't think the documentation should ever SCREAM.

 The type file has been replaced by _ioTextIOWrapper; use open() to 
 open a file; open returns an instance of _ioTextIOWrapper.

That would be an incorrect statement: there are multiple types that
replace the 2.x file type. See the documentation of the io module for
details.

--
nosy: +loewis
title: What's New should say VERY CLEARLY that the type file is gone - 
What's New should say VERY CLEARLY that the type file   is gone

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-19 Thread David W. Lambert

David W. Lambert lamber...@corning.com added the comment:

# With py3Krc1 it took me days to figure out how to
# replace my base class file.   Granted, there were
# issues with io module at the time.  Following met
# my need.


import io

class File(io.TextIOWrapper):

'''Open a text file with read access, providing...'''

def __init__(self,name):
super().__init__(open(name).buffer)

--
nosy: +LambertDW

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-19 Thread Mitchell Model

Mitchell Model m...@acm.org added the comment:

At 11:03 AM -0400 3/19/09, Mitchell L Model wrote:
Martin v. Löwis mar...@v.loewis.de added the comment:

 The Python 3 What's New should SCREAM that the type file is gone

I don't think the documentation should ever SCREAM.

No, of course not. I was being extreme. The problem with the laconic alternative
is that it sets traps for people. It reminds me of wrestling Stroustrop's first 
book
on C++ where all this weird behavior happened and when you went back to the
book you could find one sentence whose third-level implication was consistent
with the explanation. What I'm saying is that it's not enough to say to use 
open().
Don't you think people ever referred to the type file directly? As in 
help(file) or
dir(file) or file.somemethod(receiver, arg)? Or even storing a file method in a
dictionary for dispatch? It doesn't matter whether any of these were a good 
idea,
I claim they were quite ingrained in Python 2 user's minds. The changes in the
sequence types are quite substantial, but they are explained in detail. This 
isn't.

In reviewing the What's New for the purpose of this reponse I noticed an
earlier mention of sys.stdin, sys.stdout, and sys.stderr, where it says they
are now instances of TextIOBase. (They are actually instances of TextIOWrapper,
just like the result of open().) So why can't the documentation of open() say
that it returns an instance of TextIOBase too?

At least add to the paragraph of PEP 3116 that the old file type is gone.
Maybe that's better than discussing it in conjunction with open(), in which
case the statement using open() instead of file should read that open replaces
file(), not file.

It just seems like a very wide trap to never mention that the whole file type 
is gone.
It does not follow from the two facts that one should use open() instead of 
file()
and that the IO system has been rewritten, that there is no file type. Even if
whatever open returns has the same interface as the old file type.


  The type file has been replaced by _ioTextIOWrapper; use open() to
  open a file; open returns an instance of _ioTextIOWrapper.

That would be an incorrect statement: there are multiple types that
replace the 2.x file type. See the documentation of the io module for
details.

OK, I didn't follow the technical details through and, as I said above, I hadn't
noticed the earlier mention of TextIOBase for sys.stdout, etc. So just say
something like The type file is gone, replaced by classes in the IO module.
Use open() to open a file. And maybe add that it returns an instance of
TextIOBase or TextIOWrapper, whichever is deemed more appropriate.

Whatever else it says with regard to the above comments the What's New
really needs to explicitly say that the file type is gone.

And I apologize for screaming in my entry. I was just so incredibly shocked when
I figured out what was going on.
-- 

--- Mitchell

--
title: What's New should say VERY CLEARLY that the type file  is gone - 
What's New should say VERY CLEARLY that the type   fileis gone

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-19 Thread David W. Lambert

David W. Lambert lamber...@corning.com added the comment:

#OOPS!  I forgot the subtlety.
#I must also retain the stream
#else it gets collected.
#Nasty.


import io

class file(io.TextIOWrapper):

'''condensing code for this list without test is a no no!'''

def __init__(self,name):
self.stream = open(name)   # SAVE THE STREAM!
super().__init__(self.stream.buffer)

--

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-19 Thread Martin v. Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

 class file(io.TextIOWrapper):
 
 '''condensing code for this list without test is a no no!'''
 
 def __init__(self,name):
 self.stream = open(name)   # SAVE THE STREAM!
 super().__init__(self.stream.buffer)

I don't know what this is supposed to achieve, but it looks incorrect.
I would write it as

py class file(io.TextIOWrapper):
...   def __init__(self, name):
... super().__init__(io.BufferedReader(io.FileIO(name, r)))
...

Your version creates a separate TextIOWrapper for no apparent reason.

--

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-19 Thread Raymond Hettinger

Raymond Hettinger rhettin...@users.sourceforge.net added the comment:

Unassigning.  This appears to have evolved beyond the original request.

--
assignee: rhettinger - 

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-19 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

It might be helpful to provide a table in the open() docs saying what
classes in io exactly are returned for different modes.

--
nosy: +benjamin.peterson

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-18 Thread Mitchell Model

New submission from Mitchell Model m...@acm.org:

MAIN POINT

The Python 3 What's New should SCREAM that the type file is gone, not 
just that people should use the function open() to open files, since 
that has been a recommendation for quite a while.

EXPLANATION

In multiple readings of the Python 3 What's New I blew right past the 
Removed file. Use open()., since I've been using open() instead of 
file() for a long time. I didn't notice that unlike the preceding 
several lines, there were no parentheses after file and that this line 
was literally saying there was no longer a type called file.

OBSERVATIONS

(1) If the line is meant to say that you can no longer call file() as a 
function -- which would be strange if it were still a type -- then it is 
missing its parentheses.

(2) If the line is meant to say that there is no longer a file type, as 
it apparently means to say since in fact -- and to my great surprise -- 
there really IS no type called file in Python 3 (I discovered that 
doing a dir(file) to check whether file provided method function I 
thought it did instead of taking the time to look it up.) then there is 
a grammatical problem with the line since a (n old) type shouldn't be 
equated to a function call.

(3) I predict that anyone who has more than a passing acquaintance with 
Python 2 will be similarly shocked when they find out that what they get 
back from open() is a _io.TextIOWrapper (and, by the way, that they have 
to import _io or at least _io.TextIOWrapper to be able to do a dir on 
it). Likewise for help(file) and help(_io.TextIOWrapper). There should 
be a very prominent statement that as part of the reimplementation of 
the io system, the type file has been replaced by _io.TextIOWrapper.

RECOMMENDATION

The line
Removed file. Use open().
should be replaced with:
The type file has been removed; use open() to open a file.
or possibly:
The type file has been replaced by _ioTextIOWrapper; use open() to 
open a file; open returns an instance of _ioTextIOWrapper.

--
assignee: georg.brandl
components: Documentation
messages: 83783
nosy: MLModel, georg.brandl
severity: normal
status: open
title: What's New should say VERY CLEARLY that the type file is gone
versions: Python 3.0, Python 3.1

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



[issue5513] What's New should say VERY CLEARLY that the type file is gone

2009-03-18 Thread Raymond Hettinger

Raymond Hettinger rhettin...@users.sourceforge.net added the comment:

I'm working on the whatsnew updates and will make sure this is clear.

--
assignee: georg.brandl - rhettinger
nosy: +rhettinger

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