saferepr: Avoid indirect function calls

The DRY savings they provide are rather small, while they make it harder
to type-check, and IMO harder to understand.
This commit is contained in:
Ran Benita
2019-07-14 22:24:12 +03:00
parent c7aacc96bb
commit 129600d698
3 changed files with 42 additions and 23 deletions

View File

@@ -45,6 +45,17 @@ def test_exceptions():
assert "unknown" in s2
def test_buggy_builtin_repr():
# Simulate a case where a repr for a builtin raises.
# reprlib dispatches by type name, so use "int".
class int:
def __repr__(self):
raise ValueError("Buggy repr!")
assert "Buggy" in saferepr(int())
def test_big_repr():
from _pytest._io.saferepr import SafeRepr