Skip to content

Commit 86b4075

Browse files
authored
Merge pull request #3051 from Zac-HD/fix-attrs-ghost
2 parents 7cac74e + 643b4fb commit 86b4075

4 files changed

Lines changed: 21 additions & 4 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_expected_output.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ def divide(a: int, b: int) -> float:
101101
.replace("import sre_constants\n", "").replace("sre_constants.", "re."),
102102
),
103103
("re_compile_unittest", ghostwriter.fuzz(re.compile, style="unittest")),
104-
("base64_magic", ghostwriter.magic(base64)),
104+
pytest.param(
105+
("base64_magic", ghostwriter.magic(base64)),
106+
marks=pytest.mark.skipif("sys.version_info[:2] >= (3, 10)"),
107+
),
105108
("sorted_idempotent", ghostwriter.idempotent(sorted)),
106109
("timsort_idempotent", ghostwriter.idempotent(timsort)),
107110
(

‎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)