[Python-ideas] Reviving PEP 3140 - "str(container) should call str(item), not repr(item)"

Terry Jan Reedy tjreedy at udel.edu
Fri Apr 5 19:46:06 CEST 2013


On 4/4/2013 11:08 PM, Mark Janssen wrote:
>> Having str(container) calling str(item) and not repr(item) sounds like the
>> right thing to do. However, PEP 3140 was rejected on the basis of the
>> following statement of Guido:
>
> Strangely, this argument seems to get to a issue found in LISP
> regarding quoting a thing vs. the thing itself.  Python doesn't
> recognize really that distinction in its object model

Python quotes code by switching from expression to statement syntax. 
(Lambda also quotes expressions, but not, to the chagrin of some, 
statements.)

> -- though it does have a way to go the *other* direction:  type(thing).

> I think Guido's intuition is correct -- there is no logically
> "correct" way to do this.   The issue makes me think of a
> __deepstr__() method or something that one could implement if one
> wanted to print the contents of a container, but this doesn't really
> work well either.
>
> This is a problem with "everything is an object" model:  no
> recognition is made between a distinction that is very high up the
> "object taxonomy":  container vs. atomic elements.

Python does not have non-object atomic data elements.

len(ob) returning a value instead of raising an exception
distinguishes concrete collections from everything else.

iter(ob) returning instead of raising distinguishes collections 
(concrete + abstract or virtual) from everything else.

--
Terry Jan Reedy







More information about the Python-ideas mailing list