prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [Bug?] `.filter` ignored on `just` strategy
  Hi,
  I hope this has not been reported before. I checked the issues and read the [changelog] ~but could not find anything related~ and this seems to be related to issue https://github.com/HypothesisWorks/hypothesis/issues/2036.
  
  [changelog]: https://hypothesis.readthedocs.io/en/latest/changes.html
  
  I noticed an unexpected difference in the behavior when `.filter` is applied on `just` strategy between Hypothesis 5.43.3 and Hypothesis 6.12.0 (the former ran on my machine, while the remote CI machine had 6.12.0 installed).
  
  With Hypothesis 5.43.3 (expected behavior):
  ```python
  import hypothesis.strategies
  import hypothesis.strategies._internal.strategies
  
  strategy = hypothesis.strategies.just(1).filter(lambda x: x > 10)
  assert str(strategy) == "just(1).filter(lambda x: x > 10)"
  assert type(strategy) == hypothesis.strategies._internal.strategies.FilteredStrategy
  ```
  
  With Hypothesis 6.12.0 (unexpected behavior):
  
  ```python
  import hypothesis.strategies
  import hypothesis.strategies._internal.misc
  
  strategy = hypothesis.strategies.just(1).filter(lambda x: x > 10)
  assert str(strategy) == "just(1)"
  assert type(strategy) == hypothesis.strategies._internal.misc.JustStrategy
  ```
  
  This bug (?) is relevant for [icontract-hypothesis] when we test instance methods automatically where pre-conditions need to be applied on `self`. I'd expect the health check to be raised rather than the pre-conditions to be silently ignored.
  
  [icontract-hypothesis]: https://github.com/mristin/icontract-hypothesis
  
  --- 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/misc.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 hypothesis.internal.reflection import get_pretty_function_description
  17 from hypothesis.strategies._internal.strategies import (
  18     FilteredStrategy,
  19     SampledFromStrategy,
  20     SearchStrategy,
  21     T,
  22     filter_not_satisfied,
  23     is_simple_data,
  24 )
  25 from hypothesis.strategies._internal.utils import cacheable, defines_strategy
  26 
  27 
  28 class JustStrategy(SampledFromStrategy):
  29     """A strategy which always returns a single fixed value.
  30 
  31     It's implemented as a length-one SampledFromStrategy so that all our
  32     special-case logic for filtering and sets applies also to just(x).
  33 
  34     The important difference from a SampledFromStrategy with only one
  35     element to choose is that JustStrategy *never* touches the underlying
  36     choice sequence, i.e. drawing neither reads from nor writes to `data`.
  37     This is a reasonably important optimisation (or semantic distinction!)
  38     for both JustStrategy and SampledFromStrategy.
  39     """
  40 
  41     @property
  42     def value(self):
  43         return self.elements[0]
  44 
  45     def __repr__(self):
  46         if self.value is None:
  47             return "none()"
  48         return f"just({get_pretty_function_description(self.value)})"
  49 
  50     def calc_has_reusable_values(self, recur):
  51         return True
  52 
  53     def calc_is_cacheable(self, recur):
  54         return is_simple_data(self.value)
  55 
  56     def do_draw(self, data):
  57         result = self._transform(self.value)
  58         if result is filter_not_satisfied:
  59             data.note_event(f"Aborted test because unable to satisfy {self!r}")
  60             data.mark_invalid()
  61         return result
  62 
  63     def do_filtered_draw(self, data, filter_strategy):
  64         if isinstance(filter_strategy, FilteredStrategy):
  65             return self._transform(self.value, filter_strategy.flat_conditions)
  66         return self._transform(self.value)
  67 
  68 
  69 def just(value: T) -> SearchStrategy[T]:
  70     """Return a strategy which only generates ``value``.
  71 
  72     Note: ``value`` is not copied. Be wary of using mutable values.
  73 
  74     If ``value`` is the result of a callable, you can use
  75     :func:`builds(callable) <hypothesis.strategies.builds>` instead
  76     of ``just(callable())`` to get a fresh value each time.
  77 
  78     Examples from this strategy do not shrink (because there is only one).
  79     """
  80     return JustStrategy([value])
  81 
  82 
  83 @defines_strategy(force_reusable_values=True)
  84 def none() -> SearchStrategy[None]:
  85     """Return a strategy which only generates None.
  86 
  87     Examples from this strategy do not shrink (because there is only
  88     one).
  89     """
  90     return just(None)
  91 
  92 
  93 class Nothing(SearchStrategy):
  94     def calc_is_empty(self, recur):
  95         return True
  96 
  97     def do_draw(self, data):
  98         # This method should never be called because draw() will mark the
  99         # data as invalid immediately because is_empty is True.
  100         raise NotImplementedError("This should never happen")
  101 
  102     def calc_has_reusable_values(self, recur):
  103         return True
  104 
  105     def __repr__(self):
  106         return "nothing()"
  107 
  108     def map(self, f):
  109         return self
  110 
  111     def filter(self, f):
  112         return self
  113 
  114     def flatmap(self, f):
  115         return self
  116 
  117 
  118 NOTHING = Nothing()
  119 
  120 
  121 @cacheable
  122 def nothing() -> SearchStrategy:
  123     """This strategy never successfully draws a value and will always reject on
  124     an attempt to draw.
  125 
  126     Examples from this strategy do not shrink (because there are none).
  127     """
  128     return NOTHING
  129
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/misc.py b/hypothesis-python/src/hypothesis/strategies/_internal/misc.py
  --- a/hypothesis-python/src/hypothesis/strategies/_internal/misc.py
  +++ b/hypothesis-python/src/hypothesis/strategies/_internal/misc.py
  @@ -43,9 +43,13 @@
           return self.elements[0]
   
       def __repr__(self):
  +        suffix = "".join(
  +            f".{name}({get_pretty_function_description(f)})"
  +            for name, f in self._transformations
  +        )
           if self.value is None:
  -            return "none()"
  -        return f"just({get_pretty_function_description(self.value)})"
  +            return "none()" + suffix
  +        return f"just({get_pretty_function_description(self.value)}){suffix}"
   
       def calc_has_reusable_values(self, recur):
           return True
  
verification_info: {"golden_diff": "diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/misc.py b/hypothesis-python/src/hypothesis/strategies/_internal/misc.py\n--- a/hypothesis-python/src/hypothesis/strategies/_internal/misc.py\n+++ b/hypothesis-python/src/hypothesis/strategies/_internal/misc.py\n@@ -43,9 +43,13 @@\n         return self.elements[0]\n \n     def __repr__(self):\n+        suffix = \"\".join(\n+            f\".{name}({get_pretty_function_description(f)})\"\n+            for name, f in self._transformations\n+        )\n         if self.value is None:\n-            return \"none()\"\n-        return f\"just({get_pretty_function_description(self.value)})\"\n+            return \"none()\" + suffix\n+        return f\"just({get_pretty_function_description(self.value)}){suffix}\"\n \n     def calc_has_reusable_values(self, recur):\n         return True\n", "issue": "[Bug?] `.filter` ignored on `just` strategy\nHi,\r\nI hope this has not been reported before. I checked the issues and read the [changelog] ~but could not find anything related~ and this seems to be related to issue https://github.com/HypothesisWorks/hypothesis/issues/2036.\r\n\r\n[changelog]: https://hypothesis.readthedocs.io/en/latest/changes.html\r\n\r\nI noticed an unexpected difference in the behavior when `.filter` is applied on `just` strategy between Hypothesis 5.43.3 and Hypothesis 6.12.0 (the former ran on my machine, while the remote CI machine had 6.12.0 installed).\r\n\r\nWith Hypothesis 5.43.3 (expected behavior):\r\n```python\r\nimport hypothesis.strategies\r\nimport hypothesis.strategies._internal.strategies\r\n\r\nstrategy = hypothesis.strategies.just(1).filter(lambda x: x > 10)\r\nassert str(strategy) == \"just(1).filter(lambda x: x > 10)\"\r\nassert type(strategy) == hypothesis.strategies._internal.strategies.FilteredStrategy\r\n```\r\n\r\nWith Hypothesis 6.12.0 (unexpected behavior):\r\n\r\n```python\r\nimport hypothesis.strategies\r\nimport hypothesis.strategies._internal.misc\r\n\r\nstrategy = hypothesis.strategies.just(1).filter(lambda x: x > 10)\r\nassert str(strategy) == \"just(1)\"\r\nassert type(strategy) == hypothesis.strategies._internal.misc.JustStrategy\r\n```\r\n\r\nThis bug (?) is relevant for [icontract-hypothesis] when we test instance methods automatically where pre-conditions need to be applied on `self`. I'd expect the health check to be raised rather than the pre-conditions to be silently ignored.\r\n\r\n[icontract-hypothesis]: https://github.com/mristin/icontract-hypothesis\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 hypothesis.internal.reflection import get_pretty_function_description\nfrom hypothesis.strategies._internal.strategies import (\n    FilteredStrategy,\n    SampledFromStrategy,\n    SearchStrategy,\n    T,\n    filter_not_satisfied,\n    is_simple_data,\n)\nfrom hypothesis.strategies._internal.utils import cacheable, defines_strategy\n\n\nclass JustStrategy(SampledFromStrategy):\n    \"\"\"A strategy which always returns a single fixed value.\n\n    It's implemented as a length-one SampledFromStrategy so that all our\n    special-case logic for filtering and sets applies also to just(x).\n\n    The important difference from a SampledFromStrategy with only one\n    element to choose is that JustStrategy *never* touches the underlying\n    choice sequence, i.e. drawing neither reads from nor writes to `data`.\n    This is a reasonably important optimisation (or semantic distinction!)\n    for both JustStrategy and SampledFromStrategy.\n    \"\"\"\n\n    @property\n    def value(self):\n        return self.elements[0]\n\n    def __repr__(self):\n        if self.value is None:\n            return \"none()\"\n        return f\"just({get_pretty_function_description(self.value)})\"\n\n    def calc_has_reusable_values(self, recur):\n        return True\n\n    def calc_is_cacheable(self, recur):\n        return is_simple_data(self.value)\n\n    def do_draw(self, data):\n        result = self._transform(self.value)\n        if result is filter_not_satisfied:\n            data.note_event(f\"Aborted test because unable to satisfy {self!r}\")\n            data.mark_invalid()\n        return result\n\n    def do_filtered_draw(self, data, filter_strategy):\n        if isinstance(filter_strategy, FilteredStrategy):\n            return self._transform(self.value, filter_strategy.flat_conditions)\n        return self._transform(self.value)\n\n\ndef just(value: T) -> SearchStrategy[T]:\n    \"\"\"Return a strategy which only generates ``value``.\n\n    Note: ``value`` is not copied. Be wary of using mutable values.\n\n    If ``value`` is the result of a callable, you can use\n    :func:`builds(callable) <hypothesis.strategies.builds>` instead\n    of ``just(callable())`` to get a fresh value each time.\n\n    Examples from this strategy do not shrink (because there is only one).\n    \"\"\"\n    return JustStrategy([value])\n\n\n@defines_strategy(force_reusable_values=True)\ndef none() -> SearchStrategy[None]:\n    \"\"\"Return a strategy which only generates None.\n\n    Examples from this strategy do not shrink (because there is only\n    one).\n    \"\"\"\n    return just(None)\n\n\nclass Nothing(SearchStrategy):\n    def calc_is_empty(self, recur):\n        return True\n\n    def do_draw(self, data):\n        # This method should never be called because draw() will mark the\n        # data as invalid immediately because is_empty is True.\n        raise NotImplementedError(\"This should never happen\")\n\n    def calc_has_reusable_values(self, recur):\n        return True\n\n    def __repr__(self):\n        return \"nothing()\"\n\n    def map(self, f):\n        return self\n\n    def filter(self, f):\n        return self\n\n    def flatmap(self, f):\n        return self\n\n\nNOTHING = Nothing()\n\n\n@cacheable\ndef nothing() -> SearchStrategy:\n    \"\"\"This strategy never successfully draws a value and will always reject on\n    an attempt to draw.\n\n    Examples from this strategy do not shrink (because there are none).\n    \"\"\"\n    return NOTHING\n", "path": "hypothesis-python/src/hypothesis/strategies/_internal/misc.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 hypothesis.internal.reflection import get_pretty_function_description\nfrom hypothesis.strategies._internal.strategies import (\n    FilteredStrategy,\n    SampledFromStrategy,\n    SearchStrategy,\n    T,\n    filter_not_satisfied,\n    is_simple_data,\n)\nfrom hypothesis.strategies._internal.utils import cacheable, defines_strategy\n\n\nclass JustStrategy(SampledFromStrategy):\n    \"\"\"A strategy which always returns a single fixed value.\n\n    It's implemented as a length-one SampledFromStrategy so that all our\n    special-case logic for filtering and sets applies also to just(x).\n\n    The important difference from a SampledFromStrategy with only one\n    element to choose is that JustStrategy *never* touches the underlying\n    choice sequence, i.e. drawing neither reads from nor writes to `data`.\n    This is a reasonably important optimisation (or semantic distinction!)\n    for both JustStrategy and SampledFromStrategy.\n    \"\"\"\n\n    @property\n    def value(self):\n        return self.elements[0]\n\n    def __repr__(self):\n        suffix = \"\".join(\n            f\".{name}({get_pretty_function_description(f)})\"\n            for name, f in self._transformations\n        )\n        if self.value is None:\n            return \"none()\" + suffix\n        return f\"just({get_pretty_function_description(self.value)}){suffix}\"\n\n    def calc_has_reusable_values(self, recur):\n        return True\n\n    def calc_is_cacheable(self, recur):\n        return is_simple_data(self.value)\n\n    def do_draw(self, data):\n        result = self._transform(self.value)\n        if result is filter_not_satisfied:\n            data.note_event(f\"Aborted test because unable to satisfy {self!r}\")\n            data.mark_invalid()\n        return result\n\n    def do_filtered_draw(self, data, filter_strategy):\n        if isinstance(filter_strategy, FilteredStrategy):\n            return self._transform(self.value, filter_strategy.flat_conditions)\n        return self._transform(self.value)\n\n\ndef just(value: T) -> SearchStrategy[T]:\n    \"\"\"Return a strategy which only generates ``value``.\n\n    Note: ``value`` is not copied. Be wary of using mutable values.\n\n    If ``value`` is the result of a callable, you can use\n    :func:`builds(callable) <hypothesis.strategies.builds>` instead\n    of ``just(callable())`` to get a fresh value each time.\n\n    Examples from this strategy do not shrink (because there is only one).\n    \"\"\"\n    return JustStrategy([value])\n\n\n@defines_strategy(force_reusable_values=True)\ndef none() -> SearchStrategy[None]:\n    \"\"\"Return a strategy which only generates None.\n\n    Examples from this strategy do not shrink (because there is only\n    one).\n    \"\"\"\n    return just(None)\n\n\nclass Nothing(SearchStrategy):\n    def calc_is_empty(self, recur):\n        return True\n\n    def do_draw(self, data):\n        # This method should never be called because draw() will mark the\n        # data as invalid immediately because is_empty is True.\n        raise NotImplementedError(\"This should never happen\")\n\n    def calc_has_reusable_values(self, recur):\n        return True\n\n    def __repr__(self):\n        return \"nothing()\"\n\n    def map(self, f):\n        return self\n\n    def filter(self, f):\n        return self\n\n    def flatmap(self, f):\n        return self\n\n\nNOTHING = Nothing()\n\n\n@cacheable\ndef nothing() -> SearchStrategy:\n    \"\"\"This strategy never successfully draws a value and will always reject on\n    an attempt to draw.\n\n    Examples from this strategy do not shrink (because there are none).\n    \"\"\"\n    return NOTHING\n", "path": "hypothesis-python/src/hypothesis/strategies/_internal/misc.py"}]}