[ python-Feature Requests-1633665 ] file(file) should succeed

SourceForge.net noreply at sourceforge.net
Fri Jan 12 19:31:35 CET 2007


Feature Requests item #1633665, was opened at 2007-01-11 19:50
Message generated for change (Comment added) made by akuchling
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1633665&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
>Category: Python Interpreter Core
>Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 3
Private: No
Submitted By: Matthias Klose (doko)
Assigned to: Nobody/Anonymous (nobody)
Summary: file(file) should succeed

Initial Comment:
[forwarded from http://bugs.debian.org/327060]

Many types in Python are idempotent, so that int(1) works
as expected, float(2.34)==2.34, ''.join('hello')=='hello'
et cetera.

Why not file()?     Currently, file(open(something, 'r')) fails
with "TypeError: coercing to Unicode: need string or buffer, file found."

Semantically, file(fd) should be equivalent to os.fdopen(fd.fileno())
or the proposed file.fromfd() (Jp Calderone, Python-dev, 2003).
You should get another independent
file object that accesses the same file.

What would be gained?

Primarily, it would allow you to derive classes from file more easily.
At present, if you want to derive like so, you're class can only work
when passed a file name or buffer.

class file_with_caching(file):
	def __init__(self, something):
		file.__init__(self, something)
	
	def etcetera...

For instance, you have no way of creating a file_with_caching()
object from the file descriptors returned from os.fork().

Also, you have no way of taking a file that is already open,
and creating a file_with_caching() object from it.    So,
you can't use classes derived from file() on the standard input
or standard output.

This breaks the nice Linux OS-level definition of a file descriptor.
At the Linux level, you have a nice uniform interface where all
file descriptors are equally good.    At the python level, some
are better than others.   It's a case where Python unnecessarily
restricts what you can do.

----------------------------------------------------------------------

>Comment By: A.M. Kuchling (akuchling)
Date: 2007-01-12 13:31

Message:
Logged In: YES 
user_id=11375
Originator: NO

Reclassifying as feature request.

Response from GvR is at 
http://mail.python.org/pipermail/python-dev/2007-January/070591.html

This proposal probably won't be implemented; closing as "Won't fix". 
Thanks for the suggestion, though.





----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1633665&group_id=5470


More information about the Python-bugs-list mailing list