Closed as not planned
Description
Bug report
Bug description:
reprlib.repr
implements a visitor pattern which dispatches according to the typename and the module. However, changing the module and the name can lead to surprises. Ideally, we need to be able to check if an instance is an exact type and only use the visitor function for that exact type (not subtypes).
The docs don't explicitly say that exceptions are ignored for custom instances. For instance:
import reprlib
class A:
def __len__(self):
assert 0
A.__module__ = 'builtins'
A.__name__ = 'dict'
reprlib.repr(A()) # raises AssertionError as it tries len(A()) in repr_dict
I'm opening an issue to decide whether this is worth addressing or not. Should we consider code that changes dunders in such a way that checks by names and modules fail as legitimate or as "garbage in -> garbage out"?
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response