[issue4927] Inconsistent unicode repr for fileobject

Martin v. Löwis report at bugs.python.org
Fri Jan 16 00:03:21 CET 2009


Martin v. Löwis <martin at v.loewis.de> added the comment:

> I think the testsuite just exposed a design fault in python or a bug, if 
> you will.

I disagree. The feature is intentional as-is, and well-designed.

> It is customary when producing a 
> repr() of an object, to have it contain a repr() of the any inner 
> object, such as a string.

Not at all. It is customary to invoke the nested object's repr, in
the hope that the result of repr will be a string that you can pass
to eval(). This is completely different, because there is no hope
that the result of repr() of a file can be eval()ed.

As the repr is a string, it is natural to just concatenate the pieces
of the repr, including the file name string. For Unicode file names,
this natural approach fails, because one needs to encode the string
first. Mark chose to use an escape representation, because this gives
plain ASCII.

> Fixing the testsuite only, will just keep this discrepancy (or incorrect 
> string repr maybe) hidden for longer.

Right. Changing the repr will break existing code, for no good reason.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4927>
_______________________________________


More information about the Python-bugs-list mailing list