Would it be crazy to change #Python 's default repr?

Here's an example:

>>> f
<__main__.Foo object at 0x10367fca0>

The hex is the address of the Python object, and on CPython the same as id(f)

For the 99.999% case, it is useless information, and can only confuse novices.

Follow

@willmcgugan would be great if one could still look at two objects and know whether they're the same or different objects. Custom repr typically shows enough information to at least know whether they represent equivalent information, but how would a default repr ensure that?

@JakubKuczys @willmcgugan Yeah, I'm pretty sure that is why the repr includes the id information. It is *infuriating* to spend a bunch of time debugging what you think is two of the same object only to find out later they don't even compare equal or something.

@JakubKuczys Don't think it needs to. You have the id function and "is" operator.

@willmcgugan I consider being able to discern between two objects part of repr's usefulness during debugging. I expect repr to tell me enough about the object so that I don't have to look through its attributes (or id()) to learn basic things about it.

@willmcgugan not to say that discerning between objects requires id specifically but what's the alternative that would universally work in a default repr? I'm first to change default repr since I don't find it all too useful but I have to know what aspects of a specific type are useful to be able to provide a better custom repr. Having id in repr is certainly better than if it just said `<ClassName object>`

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.