Skip to content

Commit 6856f1f

Browse files
authored
Merge pull request #4440 from tybug/stateful-asdict-perf
Fix stateful test performance regression
2 parents ed6e36c + d48f1c6 commit 6856f1f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RELEASE_TYPE: patch
2+
3+
Fixes a substantial performance regression in stateful tests from computing string representations, present since :ref:`version 6.131.20 <v6.131.20>`.

hypothesis-python/src/hypothesis/internal/reflection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def get_pretty_function_description(f: object) -> str:
453453
return pretty(f)
454454
if not hasattr(f, "__name__"):
455455
return repr(f)
456-
name = f.__name__ # type: ignore # validated by hasattr above
456+
name = f.__name__ # type: ignore
457457
if name == "<lambda>":
458458
return extract_lambda_source(f)
459459
elif isinstance(f, (types.MethodType, types.BuiltinMethodType)):

hypothesis-python/src/hypothesis/stateful.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,12 @@ def __post_init__(self):
504504
self.bundles = tuple(bundles)
505505

506506
def __repr__(self) -> str:
507-
rep = get_pretty_function_description
508-
bits = [f"{k}={rep(v)}" for k, v in dataclasses.asdict(self).items() if v]
507+
bits = [
508+
f"{field.name}="
509+
f"{get_pretty_function_description(getattr(self, field.name))}"
510+
for field in dataclasses.fields(self)
511+
if getattr(self, field.name)
512+
]
509513
return f"{self.__class__.__name__}({', '.join(bits)})"
510514

511515

0 commit comments

Comments
 (0)