[Python-ideas] Reprs of classes and functions

Guido van Rossum guido at python.org
Wed Feb 25 17:21:25 CET 2015


A variant I've often wanted is to make str() return the "clean" type only
(e.g. 'int') while leaving repr() alone -- this would address most problems
Steven brought up.

On Wed, Feb 25, 2015 at 12:12 AM, Serhiy Storchaka <storchaka at gmail.com>
wrote:

> This idea is already casually mentioned, but sank deep into the threads of
> the discussion. Raise it up.
>
> Currently reprs of classes and functions look as:
>
> >>> int
> <class 'int'>
> >>> int.from_bytes
> <built-in method from_bytes of type object at 0x826cf60>
> >>> open
> <built-in function open>
> >>> import collections
> >>> collections.Counter
> <class 'collections.Counter'>
> >>> collections.Counter.fromkeys
> <bound method Counter.fromkeys of <class 'collections.Counter'>>
> >>> collections.namedtuple
> <function namedtuple at 0xb6fc4adc>
>
> What if change default reprs of classes and functions to just full
> qualified name __module__ + '.' + __qualname__ (or just __qualname__ if
> __module__ is builtins)? This will look more neatly. And such reprs are
> evaluable.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150225/8e45d5d9/attachment.html>


More information about the Python-ideas mailing list