internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: HypothesisWorks/hypothesis

Issue:
Travis pytest30 build is broken
https://travis-ci.org/HypothesisWorks/hypothesis/jobs/479698821

Not sure what changed that #1759 passed while the merged version didn't, but I think we'll just need to install an older version of `pytest-forked` too.

https://github.com/HypothesisWorks/hypothesis/blob/438c1dafe6978152cf843ba44c00efee811f8932/hypothesis-python/tox.ini#L119-L122


Discussion:

Resolving patch:
diff --git a/tooling/src/hypothesistooling/__main__.py b/tooling/src/hypothesistooling/__main__.py
--- a/tooling/src/hypothesistooling/__main__.py
+++ b/tooling/src/hypothesistooling/__main__.py
@@ -34,7 +34,10 @@
 from hypothesistooling.scripts import pip_tool
 
 TASKS = {}
-BUILD_FILES = tuple(os.path.join(tools.ROOT, f) for f in ["tooling", ".travis.yml"])
+BUILD_FILES = tuple(
+    os.path.join(tools.ROOT, f)
+    for f in ["tooling", "requirements", ".travis.yml", "hypothesis-python/tox.ini"]
+)
 
 
 def task(if_changed=()):


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
Support `range` in `st.from_type()`
The `range` builtin is actually a type - so it would be nice to support it in `st.from_type()`.

That would involve adding it via an `else:`-clause for Python 3 on the snippet below.  You'll also need to write tests in `tests/py3/test_lookup.py` to check that `from_type(range)` does in fact produce range objects; and finally add your name to the alphabetised authors list in `CONTRIBUTING.rst` and create a `hypothesis-python/RELEASE.rst` file with a changelog for a minor version (see other PRs for examples).

https://github.com/HypothesisWorks/hypothesis/blob/1a13335d38e61abb94bd7d0267488c4791ff60c7/hypothesis-python/src/hypothesis/searchstrategy/types.py#L193-L198

For `range`, the strategy might be `integers(min_value=0).map(range) | builds(integers(), integers()) | builds(integers(), integers(), integers())`.

We are explicitly *not* inviting support for `xrange`, as it has more restricted semantics around negative step sizes and Python 2 is approaching end-of-life.


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/searchstrategy/types.py b/hypothesis-python/src/hypothesis/searchstrategy/types.py
--- a/hypothesis-python/src/hypothesis/searchstrategy/types.py
+++ b/hypothesis-python/src/hypothesis/searchstrategy/types.py
@@ -196,6 +196,17 @@ def from_typing_type(thing):
         {
             int: st.integers().filter(lambda x: isinstance(x, int)),
             long: st.integers().map(long),  # noqa
+            xrange: st.integers(min_value=0).map(xrange)  # noqa
+            | st.builds(xrange, st.integers(), st.integers())  # noqa
+            | st.builds(xrange, st.integers(), st.integers(), st.integers()),  # noqa
+        }
+    )
+else:
+    _global_type_lookup.update(
+        {
+            range: st.integers(min_value=0).map(range)
+            | st.builds(range, st.integers(), st.integers())
+            | st.builds(range, st.integers(), st.integers(), st.integers())
         }
     )
 


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
Support `slice` in `st.from_type()`
The `slice` builtin is actually a type - so it would be nice to support it in `st.from_type()`.

This would involve adding it to the mapping in `hypothesis.searchstrategy.types`, as `slice: builds(slice, none() | integers(), none() | integers(), none() | integers())`, and adding a test to `tests/cover/test_type_lookup.py`.  Finally, you'll need to add your name to the list of authors in CONTRIBUTING.rst and write a changelog in `hypothesis-python/RELEASE.rst`!  (see other PRs or the contributing guide for how, or just ask :smile:)


Discussion:
Hey @Zac-HD , I'd like to take this, can I get some guidance submitting this PR? 
Check out `CONTRIBUTING.rst` in this repo to get started - that and the notes above should cover most of it.  I'm happy to answer specific questions if you have some.

(I should warn you that our `good first issue` tag means "good first contribution *to Hypothesis*", which can be pretty challenging as a new open-source contributor.  If you get a draft pull request together I'd be happy to help though :smile:)
I'll give it a try smile, just making sure I'm looking in the right place, If i understand correctly, the mapping is done in from_typing_type, which looks in the _global_type_lookup.items dict?, So I need to add it in the _global_type_lookup dict?
The lookup is done in `hypothesis._strategies.from_type`, but you're right in thinking that you need to add it to `hypothesis.searchstrategy.types._global_type_lookup`.  Just add it to the bottom of the list, just above the "pull requests welcome" comment!

https://github.com/HypothesisWorks/hypothesis/blob/a0a03770e0d53dc96158266d3fff78f03746d0a1/hypothesis-python/src/hypothesis/searchstrategy/types.py#L188-L191

FYI: check out the [GitHub markdown guide](https://guides.github.com/features/mastering-markdown/) - using "`" backticks for names from code can make things easier to read by distinguishing code from prose :smile: 
I put up a draft PR, not sure what I'm doing wrong though
It's a good start - `pip install black` and run `black .` to fix the formatting. Then add a test, changelog, and author entry as mentioned above. 
What is the test case, look up the type and see if it succeeds `st.from_type(slice).example()` ?

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/searchstrategy/types.py b/hypothesis-python/src/hypothesis/searchstrategy/types.py
--- a/hypothesis-python/src/hypothesis/searchstrategy/types.py
+++ b/hypothesis-python/src/hypothesis/searchstrategy/types.py
@@ -188,6 +188,12 @@ def from_typing_type(thing):
     numbers.Number: st.complex_numbers(),
     numbers.Integral: st.integers(),
     numbers.Complex: st.complex_numbers(),
+    slice: st.builds(
+        slice,
+        st.none() | st.integers(),
+        st.none() | st.integers(),
+        st.none() | st.integers(),
+    )
     # Pull requests with more types welcome!
 }
 


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
Fix rare bug in `st.from_type(range)`
It turns out that we missed a subtle bug when reviewing #1950: in the three-argument form of `range(start, stop, step)` (or `xrange`), `step` may be any integer *except zero*.

We would therefore like a follow-up patch that adds `.filter(bool)` to the three-argument form of both `range` and `xrange`.  You can imitate the changelog and addition to authors list from #1950; then `pip install black flake8` and run `black .` to check formatting and `flake8 --config=.flake8 .` (if on Python 3) to check that our linter is still happy.  Then open a pull request!
Fix rare bug in `st.from_type(range)`
It turns out that we missed a subtle bug when reviewing #1950: in the three-argument form of `range(start, stop, step)` (or `xrange`), `step` may be any integer *except zero*.

We would therefore like a follow-up patch that adds `.filter(bool)` to the three-argument form of both `range` and `xrange`.  You can imitate the changelog and addition to authors list from #1950; then `pip install black flake8` and run `black .` to check formatting and `flake8 --config=.flake8 .` (if on Python 3) to check that our linter is still happy.  Then open a pull request!


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/searchstrategy/types.py b/hypothesis-python/src/hypothesis/searchstrategy/types.py
--- a/hypothesis-python/src/hypothesis/searchstrategy/types.py
+++ b/hypothesis-python/src/hypothesis/searchstrategy/types.py
@@ -204,7 +204,9 @@ def from_typing_type(thing):
             long: st.integers().map(long),  # noqa
             xrange: st.integers(min_value=0).map(xrange)  # noqa
             | st.builds(xrange, st.integers(), st.integers())  # noqa
-            | st.builds(xrange, st.integers(), st.integers(), st.integers()),  # noqa
+            | st.builds(
+                xrange, st.integers(), st.integers(), st.integers().filter(bool)  # noqa
+            ),
         }
     )
 else:
@@ -212,7 +214,7 @@ def from_typing_type(thing):
         {
             range: st.integers(min_value=0).map(range)
             | st.builds(range, st.integers(), st.integers())
-            | st.builds(range, st.integers(), st.integers(), st.integers())
+            | st.builds(range, st.integers(), st.integers(), st.integers().filter(bool))
         }
     )
 


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
AttributeError: 'module' object has no attribute '_GenericAlias'
Looks like the recent `typing` update broke hypothesis (Python 2 only):

```python
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/hypothesis/internal/compat.py", line 302, in <module>
    typing_root_type = (typing._Final, typing._GenericAlias)  # type: ignore
AttributeError: 'module' object has no attribute '_GenericAlias'
```


Discussion:
@Zac-HD git blame tells me this is your code :)
Hurrah!  Looks like the underscore-means-private convention actually bit us - let's see what I can do...

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/internal/compat.py b/hypothesis-python/src/hypothesis/internal/compat.py
--- a/hypothesis-python/src/hypothesis/internal/compat.py
+++ b/hypothesis-python/src/hypothesis/internal/compat.py
@@ -298,10 +298,12 @@ def qualname(f):
     typing_root_type = ()  # type: Tuple[type, ...]
     ForwardRef = None
 else:
-    if hasattr(typing, "_Final"):  # new in Python 3.7
+    try:
+        # These types are new in Python 3.7, but also (partially) backported to the
+        # typing backport on PyPI.  Use if possible; or fall back to older names.
         typing_root_type = (typing._Final, typing._GenericAlias)  # type: ignore
         ForwardRef = typing.ForwardRef  # type: ignore
-    else:
+    except AttributeError:
         typing_root_type = (typing.TypingMeta, typing.TypeVar)  # type: ignore
         ForwardRef = typing._ForwardRef  # type: ignore
 


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
attrs 19.2 cmp warning
The just released attrs 19.2 has deprecated cmp in favor of eq/order. You can either bump the minimal version to 19.2 and move to eq or use a fw/bw-based approach like I've submitted to pytest: https://github.com/pytest-dev/pytest/pull/5902 I suspect y'all would be rather cool with just bumping the dep?


Discussion:

Resolving patch:
diff --git a/hypothesis-python/setup.py b/hypothesis-python/setup.py
--- a/hypothesis-python/setup.py
+++ b/hypothesis-python/setup.py
@@ -68,7 +68,7 @@ def local_file(name):
 extras["all"] = sorted(sum(extras.values(), []))
 
 
-install_requires = ["attrs>=16.0.0"]
+install_requires = ["attrs>=19.2.0"]
 # Using an environment marker on enum34 makes the dependency condition
 # independent of the build environemnt, which is important for wheels.
 # https://www.python.org/dev/peps/pep-0345/#environment-markers
diff --git a/hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py b/hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py
--- a/hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py
+++ b/hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py
@@ -1442,7 +1442,7 @@ def offset_left(k):
     return name
 
 
-@attr.s(slots=True, cmp=False)
+@attr.s(slots=True, eq=False)
 class ShrinkPass(object):
     run_with_chooser = attr.ib()
     index = attr.ib()
diff --git a/hypothesis-python/src/hypothesis/searchstrategy/attrs.py b/hypothesis-python/src/hypothesis/searchstrategy/attrs.py
--- a/hypothesis-python/src/hypothesis/searchstrategy/attrs.py
+++ b/hypothesis-python/src/hypothesis/searchstrategy/attrs.py
@@ -45,12 +45,12 @@ def from_attrs(target, args, kwargs, to_infer):
 
 def from_attrs_attribute(attrib, target):
     """Infer a strategy from the metadata on an attr.Attribute object."""
-    # Try inferring from the default argument.  Note that this will only help
+    # Try inferring from the default argument.  Note that this will only help if
     # the user passed `infer` to builds() for this attribute, but in that case
     # we use it as the minimal example.
     default = st.nothing()
     if isinstance(attrib.default, attr.Factory):
-        if not getattr(attrib.default, "takes_self", False):  # new in 17.1
+        if not attrib.default.takes_self:
             default = st.builds(attrib.default.factory)
     elif attrib.default is not attr.NOTHING:
         default = st.just(attrib.default)


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
Use `blacken-docs`
We use Black for our code, so why not use it for the code examples in our docs?

This should look a lot like [our pyupgrade call](https://github.com/HypothesisWorks/hypothesis/blob/8269d65f702ea564f04939ba1a5ce4eca3507554/tooling/src/hypothesistooling/__main__.py#L235), but including all `*.rst` files in the repo too.


Discussion:
Hello, I'll start looking into this 😄 

Resolving patch:
diff --git a/tooling/src/hypothesistooling/__main__.py b/tooling/src/hypothesistooling/__main__.py
--- a/tooling/src/hypothesistooling/__main__.py
+++ b/tooling/src/hypothesistooling/__main__.py
@@ -179,6 +179,9 @@ def should_format_file(path):
             return False
         return path.endswith(".py")
 
+    def should_format_doc_file(path):
+        return path.endswith((".rst", ".md"))
+
     changed = tools.modified_files()
 
     format_all = os.environ.get("FORMAT_ALL", "").lower() == "true"
@@ -189,6 +192,9 @@ def should_format_file(path):
 
     files = tools.all_files() if format_all else changed
 
+    doc_files_to_format = [f for f in sorted(files) if should_format_doc_file(f)]
+    pip_tool("blacken-docs", *doc_files_to_format)
+
     files_to_format = [f for f in sorted(files) if should_format_file(f)]
 
     if not files_to_format:


Test patch:
diff --git a/hypothesis-python/tests/cover/test_statistical_events.py b/hypothesis-python/tests/cover/test_statistical_events.py
--- a/hypothesis-python/tests/cover/test_statistical_events.py
+++ b/hypothesis-python/tests/cover/test_statistical_events.py
@@ -195,9 +195,9 @@ def test_stops_after_x_shrinks(monkeypatch):
 
     monkeypatch.setattr(engine, "MAX_SHRINKS", 0)
 
-    @given(st.integers())
+    @given(st.integers(min_value=0))
     def test(n):
-        assert n < 100
+        assert n < 10
 
     stats = call_for_statistics(test)
     assert "shrunk example" in stats.exit_reason
Repository: HypothesisWorks/hypothesis

Issue:
Attempting to draw interactively from not-a-strategy should raise InvalidArgument
Attempting to draw interactively from a non-strategy object raises an attribute error in an attempt to call `is_empty()` on the object.

E.g.
```python
 import hypothesis.strategies as st
 from hypothesis import given

@given(st.data())
def test_draw_bad(data):
    data.draw("apple")
```
```python
>>> test_draw_bad()
AttributeError: 'str' object has no attribute 'is_empty'
```

This should raise `InvalidArgument`


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/_strategies.py b/hypothesis-python/src/hypothesis/_strategies.py
--- a/hypothesis-python/src/hypothesis/_strategies.py
+++ b/hypothesis-python/src/hypothesis/_strategies.py
@@ -2142,6 +2142,7 @@ def __repr__(self):
 
     def draw(self, strategy, label=None):
         # type: (SearchStrategy[Ex], Any) -> Ex
+        check_type(SearchStrategy, strategy, "strategy")
         result = self.conjecture_data.draw(strategy)
         self.count += 1
         if label is not None:


Test patch:
diff --git a/hypothesis-python/tests/cover/test_direct_strategies.py b/hypothesis-python/tests/cover/test_direct_strategies.py
--- a/hypothesis-python/tests/cover/test_direct_strategies.py
+++ b/hypothesis-python/tests/cover/test_direct_strategies.py
@@ -456,3 +456,25 @@ def test_not_nan(xs):
         assert not math.isnan(xs)
 
     test_not_nan()
+
+
+class Sneaky(object):
+    """It's like a strategy, but it's not a strategy."""
+
+    is_empty = False
+    depth = 0
+    label = 0
+
+    def do_draw(self, data):
+        pass
+
+    def validate(self):
+        pass
+
+
+@pytest.mark.parametrize("value", [5, Sneaky()])
+@pytest.mark.parametrize("label", [None, "not a strategy"])
+@given(data=ds.data())
+def test_data_explicitly_rejects_non_strategies(data, value, label):
+    with pytest.raises(InvalidArgument):
+        data.draw(value, label=label)
Repository: HypothesisWorks/hypothesis

Issue:
Input buffers generated by the target optimiser can exceed BUFFER_SIZE
As noticed in https://github.com/HypothesisWorks/hypothesis/pull/2219#discussion_r349916836, the target optimiser can sometimes generate buffers that are longer than `BUFFER_SIZE`.

These get passed directly to `engine.cached_test_function`, which will test them as-is, bypassing the usual buffer size limit.

This probably isn't a huge problem, but it's not ideal, and might cause weird issues in the future.


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/internal/conjecture/engine.py b/hypothesis-python/src/hypothesis/internal/conjecture/engine.py
--- a/hypothesis-python/src/hypothesis/internal/conjecture/engine.py
+++ b/hypothesis-python/src/hypothesis/internal/conjecture/engine.py
@@ -155,6 +155,8 @@ def test_function(self, data):
 
         self.debug_data(data)
 
+        assert len(data.buffer) <= BUFFER_SIZE
+
         if data.status >= Status.VALID:
             for k, v in data.target_observations.items():
                 self.best_observed_targets[k] = max(self.best_observed_targets[k], v)
@@ -664,7 +666,7 @@ def cached_test_function(self, buffer):
         Otherwise we call through to ``test_function``, and return a
         fresh result.
         """
-        buffer = hbytes(buffer)
+        buffer = hbytes(buffer)[:BUFFER_SIZE]
 
         def check_result(result):
             assert result is Overrun or (


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
Internal error for unique lists
```python
from hypothesis import given, strategies as st

@given(st.lists(st.sampled_from([0, 0.0]), unique=True, min_size=1))
def t(x): pass

t()
```

triggers an assertion via `conjecture.utils.integer_range(data, lower=0, upper=-1)`


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/searchstrategy/collections.py b/hypothesis-python/src/hypothesis/searchstrategy/collections.py
--- a/hypothesis-python/src/hypothesis/searchstrategy/collections.py
+++ b/hypothesis-python/src/hypothesis/searchstrategy/collections.py
@@ -188,7 +188,7 @@ def do_draw(self, data):
 
         remaining = LazySequenceCopy(self.element_strategy.elements)
 
-        while should_draw.more():
+        while remaining and should_draw.more():
             i = len(remaining) - 1
             j = cu.integer_range(data, 0, i)
             if j != i:


Test patch:
diff --git a/hypothesis-python/tests/cover/test_sampled_from.py b/hypothesis-python/tests/cover/test_sampled_from.py
--- a/hypothesis-python/tests/cover/test_sampled_from.py
+++ b/hypothesis-python/tests/cover/test_sampled_from.py
@@ -92,3 +92,8 @@ def test_does_not_include_duplicates_even_when_duplicated_in_collection(ls):
 @given(st.lists(st.sampled_from(hrange(100)), max_size=3, unique=True))
 def test_max_size_is_respected_with_unique_sampled_from(ls):
     assert len(ls) <= 3
+
+
+@given(st.lists(st.sampled_from([0, 0.0]), unique=True, min_size=1))
+def test_issue_2247_regression(ls):
+    assert len(ls) == 1
Repository: HypothesisWorks/hypothesis

Issue:
setuptools 49.2.0 will warn if distutils is imported first
xref pypa/setuptools#2261, numpy/numpy#16851

We are trying to understand why pytest-xdist is failing to run after updating setuptools to 49.2.0. I think one problem might be [this import](https://github.com/HypothesisWorks/hypothesis/blob/master/hypothesis-python/src/hypothesis/extra/pytestplugin.py#L16). I think it would be best to `import setuptools` just before that. Although I think setuptools will move quickly to rectify that warning since it is causing much anguish across different projects, so maybe just weather the storm and wait for the next version.


Discussion:
Oh... dear.

Even if it's fixed quickly I think the net effect is that I no longer trust *stdlib `distutils`* to be free from packaging-related pain around versioning, so I'm inclined to replace it (with e.g. a regex) entirely :grimacing: 

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/extra/pytestplugin.py b/hypothesis-python/src/hypothesis/extra/pytestplugin.py
--- a/hypothesis-python/src/hypothesis/extra/pytestplugin.py
+++ b/hypothesis-python/src/hypothesis/extra/pytestplugin.py
@@ -13,7 +13,6 @@
 #
 # END HEADER
 
-from distutils.version import LooseVersion
 from inspect import signature
 
 import pytest
@@ -44,7 +43,9 @@ def __call__(self, msg):
         self.results.append(msg)
 
 
-if LooseVersion(pytest.__version__) < "4.3":  # pragma: no cover
+# Avoiding distutils.version.LooseVersion due to
+# https://github.com/HypothesisWorks/hypothesis/issues/2490
+if tuple(map(int, pytest.__version__.split(".")[:2])) < (4, 3):  # pragma: no cover
     import warnings
     from hypothesis.errors import HypothesisWarning
 


Test patch:
Repository: HypothesisWorks/hypothesis

Issue:
Add explanation for the `optional` kwarg in `fixed_dictionaries`
Currently, it is not mentioned in the docstring, so one has to do a search for #1913 and #2127 first.


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/extra/lark.py b/hypothesis-python/src/hypothesis/extra/lark.py
--- a/hypothesis-python/src/hypothesis/extra/lark.py
+++ b/hypothesis-python/src/hypothesis/extra/lark.py
@@ -24,7 +24,7 @@
 It currently only supports Lark's native EBNF syntax, but we plan to extend
 this to support other common syntaxes such as ANTLR and :rfc:`5234` ABNF.
 Lark already `supports loading grammars
-<https://github.com/lark-parser/lark#how-to-use-nearley-grammars-in-lark>`_
+<https://lark-parser.readthedocs.io/en/latest/nearley/>`_
 from `nearley.js <https://nearley.js.org/>`_, so you may not have to write
 your own at all.
 
diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/core.py b/hypothesis-python/src/hypothesis/strategies/_internal/core.py
--- a/hypothesis-python/src/hypothesis/strategies/_internal/core.py
+++ b/hypothesis-python/src/hypothesis/strategies/_internal/core.py
@@ -868,15 +868,18 @@ def fixed_dictionaries(
     optional: Dict[T, SearchStrategy[Ex]] = None
 ) -> SearchStrategy[Dict[T, Ex]]:
     """Generates a dictionary of the same type as mapping with a fixed set of
-    keys mapping to strategies. mapping must be a dict subclass.
+    keys mapping to strategies. ``mapping`` must be a dict subclass.
 
     Generated values have all keys present in mapping, with the
     corresponding values drawn from mapping[key]. If mapping is an
     instance of OrderedDict the keys will also be in the same order,
     otherwise the order is arbitrary.
 
+    If ``optional`` is passed, the generated value *may or may not* contain each
+    key from ``optional`` and a value drawn from the corresponding strategy.
+
     Examples from this strategy shrink by shrinking each individual value in
-    the generated dictionary.
+    the generated dictionary, and omitting optional key-value pairs.
     """
     check_type(dict, mapping, "mapping")
     for k, v in mapping.items():


Test patch: