On Wed, Feb 25, 2015 at 10:12:03AM +0200, Serhiy Storchaka 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
int.from_bytes open <built-in function open> import collections collections.Counter collections.Counter.fromkeys > collections.namedtuple 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.
Do you mean like this?
repr(int)
=> 'int'
repr(int.from_bytes)
=> 'int.from_bytes'
repr(open)
=> 'open'
repr(collections.Counter)
=> 'collections.Counter'
repr(collections.Counter.fromkeys)
=> 'collections.Counter.fromkeys'
repr(collections.namedtuple)
=> 'collections.namedtuple'
-1 on that idea.
The suggested repr gives no clue as to what kind of object they are. Are
they functions, methods, classes, some kind of Enum-like constant or
something special like None? That hurts the usefulness of object reprs
at the interactive interpreter. And it leads to weirdness like this:
def spam(x):
if not isinstance(x, int):
raise TypeError('expected int, got %r' % x)
# current behaviour
spam(int)
=> TypeError: expected int, got