[issue13224] Change str(x) to return only the qualname for some types

Vedran Čačić report at bugs.python.org
Tue Sep 19 04:42:48 EDT 2017


Vedran Čačić added the comment:

getname sounds good, but is in fact very confusing. In most cases, what you'd actually want, and end up writing, is getname(type(x)), but we can't make it the default since for classes we would actually like x.__name__ directly. It seems you say the same with "get the names of various things (e.g. via `__class__`)", but the interface is very complicated if we try to guess what people meant, and clumsy if we force people to write type almost all the time.

The point is, we want to be explicit about whether we are speaking about x or type(x). Everything else is simply presentation details. type does it perfectly well, only the presentation details are canonically handled via str and repr. And it's perfectly natural, BTW. Imagine if str(5) gave you '<integer 5>'. :-o

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue13224>
_______________________________________


More information about the Python-bugs-list mailing list