Skip to content

Commit a65d407

Browse files
committed
Fix attrs+ghostwriter bug
1 parent 9d4da6c commit a65d407

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎hypothesis-python/RELEASE.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch fixes :issue:`3050`, where :pypi:`attrs` classes could
4+
cause an internal error in the :doc:`ghostwriter <ghostwriter>`.

‎hypothesis-python/src/hypothesis/strategies/_internal/attrs.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from hypothesis import strategies as st
2222
from hypothesis.errors import ResolutionFailed
2323
from hypothesis.internal.compat import get_type_hints
24+
from hypothesis.strategies._internal.core import BuildsStrategy
2425
from hypothesis.strategies._internal.types import is_a_type, type_sorting_key
2526
from hypothesis.utils.conventions import infer
2627

@@ -34,9 +35,7 @@ def from_attrs(target, args, kwargs, to_infer):
3435
# We might make this strategy more efficient if we added a layer here that
3536
# retries drawing if validation fails, for improved composition.
3637
# The treatment of timezones in datetimes() provides a precedent.
37-
return st.tuples(st.tuples(*args), st.fixed_dictionaries(kwargs)).map(
38-
lambda value: target(*value[0], **value[1])
39-
)
38+
return BuildsStrategy(target, args, kwargs)
4039

4140

4241
def from_attrs_attribute(attrib, target):

‎hypothesis-python/tests/ghostwriter/test_ghostwriter.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
ValuesView,
3737
)
3838

39+
import attr
3940
import pytest
4041

4142
from hypothesis.errors import InvalidArgument, MultipleFailures, Unsatisfiable
@@ -164,6 +165,15 @@ def takes_frozensets(a: FrozenSet[int], b: FrozenSet[int]) -> None:
164165
pass
165166

166167

168+
@attr.s()
169+
class Foo:
170+
foo: str = attr.ib()
171+
172+
173+
def takes_attrs_class(x: Foo) -> None:
174+
pass
175+
176+
167177
@varied_excepts
168178
@pytest.mark.parametrize(
169179
"func",
@@ -183,6 +193,7 @@ def takes_frozensets(a: FrozenSet[int], b: FrozenSet[int]) -> None:
183193
takes_pattern,
184194
takes_sized,
185195
takes_frozensets,
196+
takes_attrs_class,
186197
],
187198
)
188199
def test_ghostwriter_fuzz(func, ex):

0 commit comments

Comments
 (0)