This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: file(file) should succeed
Type: enhancement Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: akuchling, doko
Priority: low Keywords:

Created on 2007-01-12 00:50 by doko, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg54972 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2007-01-12 00:50
[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.
msg54973 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2007-01-12 18:31
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.



History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44446
2007-01-12 00:50:33dokocreate