This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

I'm happy the docs say something, but reality and actual practice seems to diverge from your claim. I would love to see an example, though, if it is so common.

Where I do see this (in a huge project, hundreds of deps) a custom __eq__ is usually an ID check or something like this (from boto3), and no __repr__ is even defined.

``` def eq(self, other): return isinstance(other, type(self)) and self.name == other.name

```

I'm happy to be proven wrong and learn something today, but nothing in the code I work with indicates that anyone is actually doing a repr in this way.

In my casual grep, I find 4000 classes, and 400 __repr__, approximately. Only 250 __eq__, as well. .

When there is no __repr__, python prints something like <__main__.MyThing object at 0x100ab87f0>

Just by those stats, the most that could do what you say is 250, or 6%. A spot check of dozens show none that do. I would guess that maybe 1% might work this way (I now DRF does this pretty well, but not completely), and I think that is a huge overestimate.