We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Ghostwriter error on attrs class
While playing around with the ghostwriter today, I got an exception like this one running it against some internal code:

```
Traceback (most recent call last):
  File "/tmp/repro/venv/bin/hypothesis", line 8, in <module>
    sys.exit(main())
  File "/tmp/repro/venv/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/tmp/repro/venv/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/tmp/repro/venv/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/tmp/repro/venv/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmp/repro/venv/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/cli.py", line 242, in write
    code = getattr(ghostwriter, writer)(*func, except_=except_ or (), style=style)
  File "/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py", line 882, in magic
    make_(
  File "/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py", line 802, in make_
    imp, body = how(*args, **kwargs, except_=except_, style=style)
  File "/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py", line 626, in _make_test_body
    given_strategies = given_strategies or _get_strategies(
  File "/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py", line 409, in _get_strategies
    if strat.args:
AttributeError: 'MappedSearchStrategy' object has no attribute 'args'
```

I reduced the input to trigger this exception down to

```python
import attr

@attr.s()
class Foo:
    foo: str = attr.ib()
```

I saw this with cPython 3.9.6, attrs 21.2.0, and hypothesis master branch at hypothesis-python-6.14.5-5-g9d4da6c2f. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `hypothesis-python/src/hypothesis/strategies/_internal/attrs.py`
Content:
```
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Most of this work is copyright (C) 2013-2021 David R. MacIver
5 # (david@drmaciver.com), but it contains contributions by others. See
6 # CONTRIBUTING.rst for a full list of people who may hold copyright, and
7 # consult the git log if you need to determine who owns an individual
8 # contribution.
9 #
10 # This Source Code Form is subject to the terms of the Mozilla Public License,
11 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
12 # obtain one at https://mozilla.org/MPL/2.0/.
13 #
14 # END HEADER
15 
16 from functools import reduce
17 from itertools import chain
18 
19 import attr
20 
21 from hypothesis import strategies as st
22 from hypothesis.errors import ResolutionFailed
23 from hypothesis.internal.compat import get_type_hints
24 from hypothesis.strategies._internal.types import is_a_type, type_sorting_key
25 from hypothesis.utils.conventions import infer
26 
27 
28 def from_attrs(target, args, kwargs, to_infer):
29     """An internal version of builds(), specialised for Attrs classes."""
30     fields = attr.fields(target)
31     kwargs = {k: v for k, v in kwargs.items() if v is not infer}
32     for name in to_infer:
33         kwargs[name] = from_attrs_attribute(getattr(fields, name), target)
34     # We might make this strategy more efficient if we added a layer here that
35     # retries drawing if validation fails, for improved composition.
36     # 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     )
40 
41 
42 def from_attrs_attribute(attrib, target):
43     """Infer a strategy from the metadata on an attr.Attribute object."""
44     # Try inferring from the default argument.  Note that this will only help if
45     # the user passed `infer` to builds() for this attribute, but in that case
46     # we use it as the minimal example.
47     default = st.nothing()
48     if isinstance(attrib.default, attr.Factory):
49         if not attrib.default.takes_self:
50             default = st.builds(attrib.default.factory)
51     elif attrib.default is not attr.NOTHING:
52         default = st.just(attrib.default)
53 
54     # Try inferring None, exact values, or type from attrs provided validators.
55     null = st.nothing()  # updated to none() on seeing an OptionalValidator
56     in_collections = []  # list of in_ validator collections to sample from
57     validator_types = set()  # type constraints to pass to types_to_strategy()
58     if attrib.validator is not None:
59         validator = attrib.validator
60         if isinstance(validator, attr.validators._OptionalValidator):
61             null = st.none()
62             validator = validator.validator
63         if isinstance(validator, attr.validators._AndValidator):
64             vs = validator._validators
65         else:
66             vs = [validator]
67         for v in vs:
68             if isinstance(v, attr.validators._InValidator):
69                 if isinstance(v.options, str):
70                     in_collections.append(list(all_substrings(v.options)))
71                 else:
72                     in_collections.append(v.options)
73             elif isinstance(v, attr.validators._InstanceOfValidator):
74                 validator_types.add(v.type)
75 
76     # This is the important line.  We compose the final strategy from various
77     # parts.  The default value, if any, is the minimal shrink, followed by
78     # None (again, if allowed).  We then prefer to sample from values passed
79     # to an in_ validator if available, but infer from a type otherwise.
80     # Pick one because (sampled_from((1, 2)) | from_type(int)) would usually
81     # fail validation by generating e.g. zero!
82     if in_collections:
83         sample = st.sampled_from(list(ordered_intersection(in_collections)))
84         strat = default | null | sample
85     else:
86         strat = default | null | types_to_strategy(attrib, validator_types)
87 
88     # Better to give a meaningful error here than an opaque "could not draw"
89     # when we try to get a value but have lost track of where this was created.
90     if strat.is_empty:
91         raise ResolutionFailed(
92             "Cannot infer a strategy from the default, validator, type, or "
93             "converter for attribute=%r of class=%r" % (attrib, target)
94         )
95     return strat
96 
97 
98 def types_to_strategy(attrib, types):
99     """Find all the type metadata for this attribute, reconcile it, and infer a
100     strategy from the mess."""
101     # If we know types from the validator(s), that's sufficient.
102     if len(types) == 1:
103         (typ,) = types
104         if isinstance(typ, tuple):
105             return st.one_of(*map(st.from_type, typ))
106         return st.from_type(typ)
107     elif types:
108         # We have a list of tuples of types, and want to find a type
109         # (or tuple of types) that is a subclass of all of of them.
110         type_tuples = [k if isinstance(k, tuple) else (k,) for k in types]
111         # Flatten the list, filter types that would fail validation, and
112         # sort so that ordering is stable between runs and shrinks well.
113         allowed = [
114             t
115             for t in set(sum(type_tuples, ()))
116             if all(issubclass(t, tup) for tup in type_tuples)
117         ]
118         allowed.sort(key=type_sorting_key)
119         return st.one_of([st.from_type(t) for t in allowed])
120 
121     # Otherwise, try the `type` attribute as a fallback, and finally try
122     # the type hints on a converter (desperate!) before giving up.
123     if is_a_type(getattr(attrib, "type", None)):
124         # The convoluted test is because variable annotations may be stored
125         # in string form; attrs doesn't evaluate them and we don't handle them.
126         # See PEP 526, PEP 563, and Hypothesis issue #1004 for details.
127         return st.from_type(attrib.type)
128 
129     converter = getattr(attrib, "converter", None)
130     if isinstance(converter, type):
131         return st.from_type(converter)
132     elif callable(converter):
133         hints = get_type_hints(converter)
134         if "return" in hints:
135             return st.from_type(hints["return"])
136 
137     return st.nothing()
138 
139 
140 def ordered_intersection(in_):
141     """Set union of n sequences, ordered for reproducibility across runs."""
142     intersection = reduce(set.intersection, in_, set(in_[0]))
143     for x in chain.from_iterable(in_):
144         if x in intersection:
145             yield x
146             intersection.remove(x)
147 
148 
149 def all_substrings(s):
150     """Generate all substrings of `s`, in order of length then occurrence.
151     Includes the empty string (first), and any duplicates that are present.
152 
153     >>> list(all_substrings('010'))
154     ['', '0', '1', '0', '01', '10', '010']
155     """
156     yield s[:0]
157     for n, _ in enumerate(s):
158         for i in range(len(s) - n):
159             yield s[i : i + n + 1]
160
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py b/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py
--- a/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py
+++ b/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py
@@ -21,6 +21,7 @@
 from hypothesis import strategies as st
 from hypothesis.errors import ResolutionFailed
 from hypothesis.internal.compat import get_type_hints
+from hypothesis.strategies._internal.core import BuildsStrategy
 from hypothesis.strategies._internal.types import is_a_type, type_sorting_key
 from hypothesis.utils.conventions import infer
 
@@ -34,9 +35,7 @@
     # We might make this strategy more efficient if we added a layer here that
     # retries drawing if validation fails, for improved composition.
     # The treatment of timezones in datetimes() provides a precedent.
-    return st.tuples(st.tuples(*args), st.fixed_dictionaries(kwargs)).map(
-        lambda value: target(*value[0], **value[1])
-    )
+    return BuildsStrategy(target, args, kwargs)
 
 
 def from_attrs_attribute(attrib, target):

{"golden_diff": "diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py b/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py\n--- a/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py\n+++ b/hypothesis-python/src/hypothesis/strategies/_internal/attrs.py\n@@ -21,6 +21,7 @@\n from hypothesis import strategies as st\n from hypothesis.errors import ResolutionFailed\n from hypothesis.internal.compat import get_type_hints\n+from hypothesis.strategies._internal.core import BuildsStrategy\n from hypothesis.strategies._internal.types import is_a_type, type_sorting_key\n from hypothesis.utils.conventions import infer\n \n@@ -34,9 +35,7 @@\n     # We might make this strategy more efficient if we added a layer here that\n     # retries drawing if validation fails, for improved composition.\n     # The treatment of timezones in datetimes() provides a precedent.\n-    return st.tuples(st.tuples(*args), st.fixed_dictionaries(kwargs)).map(\n-        lambda value: target(*value[0], **value[1])\n-    )\n+    return BuildsStrategy(target, args, kwargs)\n \n \n def from_attrs_attribute(attrib, target):\n", "issue": "Ghostwriter error on attrs class\nWhile playing around with the ghostwriter today, I got an exception like this one running it against some internal code:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/tmp/repro/venv/bin/hypothesis\", line 8, in <module>\r\n    sys.exit(main())\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/click/core.py\", line 1137, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/click/core.py\", line 1062, in main\r\n    rv = self.invoke(ctx)\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/click/core.py\", line 1668, in invoke\r\n    return _process_result(sub_ctx.command.invoke(sub_ctx))\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/click/core.py\", line 1404, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/click/core.py\", line 763, in invoke\r\n    return __callback(*args, **kwargs)\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/cli.py\", line 242, in write\r\n    code = getattr(ghostwriter, writer)(*func, except_=except_ or (), style=style)\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py\", line 882, in magic\r\n    make_(\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py\", line 802, in make_\r\n    imp, body = how(*args, **kwargs, except_=except_, style=style)\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py\", line 626, in _make_test_body\r\n    given_strategies = given_strategies or _get_strategies(\r\n  File \"/tmp/repro/venv/lib/python3.9/site-packages/hypothesis/extra/ghostwriter.py\", line 409, in _get_strategies\r\n    if strat.args:\r\nAttributeError: 'MappedSearchStrategy' object has no attribute 'args'\r\n```\r\n\r\nI reduced the input to trigger this exception down to\r\n\r\n```python\r\nimport attr\r\n\r\n@attr.s()\r\nclass Foo:\r\n    foo: str = attr.ib()\r\n```\r\n\r\nI saw this with cPython 3.9.6, attrs 21.2.0, and hypothesis master branch at hypothesis-python-6.14.5-5-g9d4da6c2f. \n", "before_files": [{"content": "# This file is part of Hypothesis, which may be found at\n# https://github.com/HypothesisWorks/hypothesis/\n#\n# Most of this work is copyright (C) 2013-2021 David R. MacIver\n# (david@drmaciver.com), but it contains contributions by others. See\n# CONTRIBUTING.rst for a full list of people who may hold copyright, and\n# consult the git log if you need to determine who owns an individual\n# contribution.\n#\n# This Source Code Form is subject to the terms of the Mozilla Public License,\n# v. 2.0. If a copy of the MPL was not distributed with this file, You can\n# obtain one at https://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom functools import reduce\nfrom itertools import chain\n\nimport attr\n\nfrom hypothesis import strategies as st\nfrom hypothesis.errors import ResolutionFailed\nfrom hypothesis.internal.compat import get_type_hints\nfrom hypothesis.strategies._internal.types import is_a_type, type_sorting_key\nfrom hypothesis.utils.conventions import infer\n\n\ndef from_attrs(target, args, kwargs, to_infer):\n    \"\"\"An internal version of builds(), specialised for Attrs classes.\"\"\"\n    fields = attr.fields(target)\n    kwargs = {k: v for k, v in kwargs.items() if v is not infer}\n    for name in to_infer:\n        kwargs[name] = from_attrs_attribute(getattr(fields, name), target)\n    # We might make this strategy more efficient if we added a layer here that\n    # retries drawing if validation fails, for improved composition.\n    # The treatment of timezones in datetimes() provides a precedent.\n    return st.tuples(st.tuples(*args), st.fixed_dictionaries(kwargs)).map(\n        lambda value: target(*value[0], **value[1])\n    )\n\n\ndef from_attrs_attribute(attrib, target):\n    \"\"\"Infer a strategy from the metadata on an attr.Attribute object.\"\"\"\n    # Try inferring from the default argument.  Note that this will only help if\n    # the user passed `infer` to builds() for this attribute, but in that case\n    # we use it as the minimal example.\n    default = st.nothing()\n    if isinstance(attrib.default, attr.Factory):\n        if not attrib.default.takes_self:\n            default = st.builds(attrib.default.factory)\n    elif attrib.default is not attr.NOTHING:\n        default = st.just(attrib.default)\n\n    # Try inferring None, exact values, or type from attrs provided validators.\n    null = st.nothing()  # updated to none() on seeing an OptionalValidator\n    in_collections = []  # list of in_ validator collections to sample from\n    validator_types = set()  # type constraints to pass to types_to_strategy()\n    if attrib.validator is not None:\n        validator = attrib.validator\n        if isinstance(validator, attr.validators._OptionalValidator):\n            null = st.none()\n            validator = validator.validator\n        if isinstance(validator, attr.validators._AndValidator):\n            vs = validator._validators\n        else:\n            vs = [validator]\n        for v in vs:\n            if isinstance(v, attr.validators._InValidator):\n                if isinstance(v.options, str):\n                    in_collections.append(list(all_substrings(v.options)))\n                else:\n                    in_collections.append(v.options)\n            elif isinstance(v, attr.validators._InstanceOfValidator):\n                validator_types.add(v.type)\n\n    # This is the important line.  We compose the final strategy from various\n    # parts.  The default value, if any, is the minimal shrink, followed by\n    # None (again, if allowed).  We then prefer to sample from values passed\n    # to an in_ validator if available, but infer from a type otherwise.\n    # Pick one because (sampled_from((1, 2)) | from_type(int)) would usually\n    # fail validation by generating e.g. zero!\n    if in_collections:\n        sample = st.sampled_from(list(ordered_intersection(in_collections)))\n        strat = default | null | sample\n    else:\n        strat = default | null | types_to_strategy(attrib, validator_types)\n\n    # Better to give a meaningful error here than an opaque \"could not draw\"\n    # when we try to get a value but have lost track of where this was created.\n    if strat.is_empty:\n        raise ResolutionFailed(\n            \"Cannot infer a strategy from the default, validator, type, or \"\n            \"converter for attribute=%r of class=%r\" % (attrib, target)\n        )\n    return strat\n\n\ndef types_to_strategy(attrib, types):\n    \"\"\"Find all the type metadata for this attribute, reconcile it, and infer a\n    strategy from the mess.\"\"\"\n    # If we know types from the validator(s), that's sufficient.\n    if len(types) == 1:\n        (typ,) = types\n        if isinstance(typ, tuple):\n            return st.one_of(*map(st.from_type, typ))\n        return st.from_type(typ)\n    elif types:\n        # We have a list of tuples of types, and want to find a type\n        # (or tuple of types) that is a subclass of all of of them.\n        type_tuples = [k if isinstance(k, tuple) else (k,) for k in types]\n        # Flatten the list, filter types that would fail validation, and\n        # sort so that ordering is stable between runs and shrinks well.\n        allowed = [\n            t\n            for t in set(sum(type_tuples, ()))\n            if all(issubclass(t, tup) for tup in type_tuples)\n        ]\n        allowed.sort(key=type_sorting_key)\n        return st.one_of([st.from_type(t) for t in allowed])\n\n    # Otherwise, try the `type` attribute as a fallback, and finally try\n    # the type hints on a converter (desperate!) before giving up.\n    if is_a_type(getattr(attrib, \"type\", None)):\n        # The convoluted test is because variable annotations may be stored\n        # in string form; attrs doesn't evaluate them and we don't handle them.\n        # See PEP 526, PEP 563, and Hypothesis issue #1004 for details.\n        return st.from_type(attrib.type)\n\n    converter = getattr(attrib, \"converter\", None)\n    if isinstance(converter, type):\n        return st.from_type(converter)\n    elif callable(converter):\n        hints = get_type_hints(converter)\n        if \"return\" in hints:\n            return st.from_type(hints[\"return\"])\n\n    return st.nothing()\n\n\ndef ordered_intersection(in_):\n    \"\"\"Set union of n sequences, ordered for reproducibility across runs.\"\"\"\n    intersection = reduce(set.intersection, in_, set(in_[0]))\n    for x in chain.from_iterable(in_):\n        if x in intersection:\n            yield x\n            intersection.remove(x)\n\n\ndef all_substrings(s):\n    \"\"\"Generate all substrings of `s`, in order of length then occurrence.\n    Includes the empty string (first), and any duplicates that are present.\n\n    >>> list(all_substrings('010'))\n    ['', '0', '1', '0', '01', '10', '010']\n    \"\"\"\n    yield s[:0]\n    for n, _ in enumerate(s):\n        for i in range(len(s) - n):\n            yield s[i : i + n + 1]\n", "path": "hypothesis-python/src/hypothesis/strategies/_internal/attrs.py"}], "after_files": [{"content": "# This file is part of Hypothesis, which may be found at\n# https://github.com/HypothesisWorks/hypothesis/\n#\n# Most of this work is copyright (C) 2013-2021 David R. MacIver\n# (david@drmaciver.com), but it contains contributions by others. See\n# CONTRIBUTING.rst for a full list of people who may hold copyright, and\n# consult the git log if you need to determine who owns an individual\n# contribution.\n#\n# This Source Code Form is subject to the terms of the Mozilla Public License,\n# v. 2.0. If a copy of the MPL was not distributed with this file, You can\n# obtain one at https://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom functools import reduce\nfrom itertools import chain\n\nimport attr\n\nfrom hypothesis import strategies as st\nfrom hypothesis.errors import ResolutionFailed\nfrom hypothesis.internal.compat import get_type_hints\nfrom hypothesis.strategies._internal.core import BuildsStrategy\nfrom hypothesis.strategies._internal.types import is_a_type, type_sorting_key\nfrom hypothesis.utils.conventions import infer\n\n\ndef from_attrs(target, args, kwargs, to_infer):\n    \"\"\"An internal version of builds(), specialised for Attrs classes.\"\"\"\n    fields = attr.fields(target)\n    kwargs = {k: v for k, v in kwargs.items() if v is not infer}\n    for name in to_infer:\n        kwargs[name] = from_attrs_attribute(getattr(fields, name), target)\n    # We might make this strategy more efficient if we added a layer here that\n    # retries drawing if validation fails, for improved composition.\n    # The treatment of timezones in datetimes() provides a precedent.\n    return BuildsStrategy(target, args, kwargs)\n\n\ndef from_attrs_attribute(attrib, target):\n    \"\"\"Infer a strategy from the metadata on an attr.Attribute object.\"\"\"\n    # Try inferring from the default argument.  Note that this will only help if\n    # the user passed `infer` to builds() for this attribute, but in that case\n    # we use it as the minimal example.\n    default = st.nothing()\n    if isinstance(attrib.default, attr.Factory):\n        if not attrib.default.takes_self:\n            default = st.builds(attrib.default.factory)\n    elif attrib.default is not attr.NOTHING:\n        default = st.just(attrib.default)\n\n    # Try inferring None, exact values, or type from attrs provided validators.\n    null = st.nothing()  # updated to none() on seeing an OptionalValidator\n    in_collections = []  # list of in_ validator collections to sample from\n    validator_types = set()  # type constraints to pass to types_to_strategy()\n    if attrib.validator is not None:\n        validator = attrib.validator\n        if isinstance(validator, attr.validators._OptionalValidator):\n            null = st.none()\n            validator = validator.validator\n        if isinstance(validator, attr.validators._AndValidator):\n            vs = validator._validators\n        else:\n            vs = [validator]\n        for v in vs:\n            if isinstance(v, attr.validators._InValidator):\n                if isinstance(v.options, str):\n                    in_collections.append(list(all_substrings(v.options)))\n                else:\n                    in_collections.append(v.options)\n            elif isinstance(v, attr.validators._InstanceOfValidator):\n                validator_types.add(v.type)\n\n    # This is the important line.  We compose the final strategy from various\n    # parts.  The default value, if any, is the minimal shrink, followed by\n    # None (again, if allowed).  We then prefer to sample from values passed\n    # to an in_ validator if available, but infer from a type otherwise.\n    # Pick one because (sampled_from((1, 2)) | from_type(int)) would usually\n    # fail validation by generating e.g. zero!\n    if in_collections:\n        sample = st.sampled_from(list(ordered_intersection(in_collections)))\n        strat = default | null | sample\n    else:\n        strat = default | null | types_to_strategy(attrib, validator_types)\n\n    # Better to give a meaningful error here than an opaque \"could not draw\"\n    # when we try to get a value but have lost track of where this was created.\n    if strat.is_empty:\n        raise ResolutionFailed(\n            \"Cannot infer a strategy from the default, validator, type, or \"\n            \"converter for attribute=%r of class=%r\" % (attrib, target)\n        )\n    return strat\n\n\ndef types_to_strategy(attrib, types):\n    \"\"\"Find all the type metadata for this attribute, reconcile it, and infer a\n    strategy from the mess.\"\"\"\n    # If we know types from the validator(s), that's sufficient.\n    if len(types) == 1:\n        (typ,) = types\n        if isinstance(typ, tuple):\n            return st.one_of(*map(st.from_type, typ))\n        return st.from_type(typ)\n    elif types:\n        # We have a list of tuples of types, and want to find a type\n        # (or tuple of types) that is a subclass of all of of them.\n        type_tuples = [k if isinstance(k, tuple) else (k,) for k in types]\n        # Flatten the list, filter types that would fail validation, and\n        # sort so that ordering is stable between runs and shrinks well.\n        allowed = [\n            t\n            for t in set(sum(type_tuples, ()))\n            if all(issubclass(t, tup) for tup in type_tuples)\n        ]\n        allowed.sort(key=type_sorting_key)\n        return st.one_of([st.from_type(t) for t in allowed])\n\n    # Otherwise, try the `type` attribute as a fallback, and finally try\n    # the type hints on a converter (desperate!) before giving up.\n    if is_a_type(getattr(attrib, \"type\", None)):\n        # The convoluted test is because variable annotations may be stored\n        # in string form; attrs doesn't evaluate them and we don't handle them.\n        # See PEP 526, PEP 563, and Hypothesis issue #1004 for details.\n        return st.from_type(attrib.type)\n\n    converter = getattr(attrib, \"converter\", None)\n    if isinstance(converter, type):\n        return st.from_type(converter)\n    elif callable(converter):\n        hints = get_type_hints(converter)\n        if \"return\" in hints:\n            return st.from_type(hints[\"return\"])\n\n    return st.nothing()\n\n\ndef ordered_intersection(in_):\n    \"\"\"Set union of n sequences, ordered for reproducibility across runs.\"\"\"\n    intersection = reduce(set.intersection, in_, set(in_[0]))\n    for x in chain.from_iterable(in_):\n        if x in intersection:\n            yield x\n            intersection.remove(x)\n\n\ndef all_substrings(s):\n    \"\"\"Generate all substrings of `s`, in order of length then occurrence.\n    Includes the empty string (first), and any duplicates that are present.\n\n    >>> list(all_substrings('010'))\n    ['', '0', '1', '0', '01', '10', '010']\n    \"\"\"\n    yield s[:0]\n    for n, _ in enumerate(s):\n        for i in range(len(s) - n):\n            yield s[i : i + n + 1]\n", "path": "hypothesis-python/src/hypothesis/strategies/_internal/attrs.py"}]}