nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jazzband/pip-tools
Pull request #763 (2019-03-11 16:24:24)

Write markers before hashes to fix issues.
Fixes issue with generated lock file when hashes and markers are used together.

**Changelog-friendly one-liner**:  Fix order issue with generated lock file when hashes and markers are used together.

##### Contributor checklist

- [x] Provided the tests for the changes.
- [x] Requested a review from another contributor.
- [x] Gave a clear one-line description in the PR (that the maintainers can add to CHANGELOG.md on release).
- [x] Assign the PR to an existing or new milestone for the target version (following [Semantic Versioning](https://blog.versioneye.com/2014/01/16/semantic-versioning/)).


milind-shakya-sp: @atugushev Please review when you get a chance.

Patch:
diff --git a/piptools/utils.py b/piptools/utils.py
index cb04170..9b4b4c2 100644
--- a/piptools/utils.py
+++ b/piptools/utils.py
@@ -61,13 +61,13 @@ def format_requirement(ireq, marker=None, hashes=None):
     else:
         line = str(ireq.req).lower()
 
+    if marker:
+        line = '{} ; {}'.format(line, marker)
+
     if hashes:
         for hash_ in sorted(hashes):
             line += " \\\n    --hash={}".format(hash_)
 
-    if marker:
-        line = '{} ; {}'.format(line, marker)
-
     return line
 
 


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index a43c116..2db48df 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -30,6 +30,22 @@ def test_format_requirement_ireq_with_hashes(from_line):
     assert format_requirement(ireq, hashes=ireq_hashes) == expected
 
 
+def test_format_requirement_ireq_with_hashes_and_markers(from_line):
+    ireq = from_line('pytz==2017.2')
+    marker = 'python_version<"3.0"'
+    ireq_hashes = [
+        'sha256:d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67',
+        'sha256:f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589',
+    ]
+
+    expected = (
+        'pytz==2017.2 ; python_version<"3.0" \\\n'
+        '    --hash=sha256:d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67 \\\n'
+        '    --hash=sha256:f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589'
+    )
+    assert format_requirement(ireq, marker, hashes=ireq_hashes) == expected
+
+
 def test_format_specifier(from_line):
     ireq = from_line('foo')
     assert format_specifier(ireq) == '<any>'
Repository: jazzband/pip-tools
Pull request #765 (2019-03-19 04:20:20)

Show less output on sync with quiet option
Doesn't show "Everything up-to-date" if quiet option is set.

**Changelog-friendly one-liner**: Show less output on sync with quiet option

##### Contributor checklist

- [X] Provided the tests for the changes.
- [X] Requested a review from another contributor.
- [X] Gave a clear one-line description in the PR (that the maintainers can add to CHANGELOG.md on release).
- [x] Assign the PR to an existing or new milestone for the target version (following [Semantic Versioning](https://blog.versioneye.com/2014/01/16/semantic-versioning/)).



Patch:
diff --git a/piptools/sync.py b/piptools/sync.py
index f111764..b882ba3 100644
--- a/piptools/sync.py
+++ b/piptools/sync.py
@@ -125,7 +125,9 @@ def sync(to_install, to_uninstall, verbose=False, dry_run=False, install_flags=N
     Install and uninstalls the given sets of modules.
     """
     if not to_uninstall and not to_install:
-        click.echo("Everything up-to-date")
+        if verbose:
+            click.echo("Everything up-to-date")
+        return 0
 
     pip_flags = []
     if not verbose:


Test patch:
diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py
index 285a719..961c65a 100644
--- a/tests/test_cli_sync.py
+++ b/tests/test_cli_sync.py
@@ -39,6 +39,22 @@ def test_quiet_option(tmpdir):
                 assert '-q' in call[0][0]
 
 
+@mock.patch('piptools.sync.check_call')
+def test_quiet_option_when_up_to_date(check_call, runner):
+    """
+    Sync should output nothing when everything is up to date and quiet option is set.
+    """
+    with open('requirements.txt', 'w'):
+        pass
+
+    with mock.patch('piptools.sync.diff', return_value=(set(), set())):
+        out = runner.invoke(cli, ['-q'])
+
+    assert out.output == ''
+    assert out.exit_code == 0
+    check_call.assert_not_called()
+
+
 def test_no_requirements_file(runner):
     """
     It should raise an error if there are no input files
diff --git a/tests/test_sync.py b/tests/test_sync.py
index 49677bd..80a14a6 100644
--- a/tests/test_sync.py
+++ b/tests/test_sync.py
@@ -328,7 +328,7 @@ def test_sync_up_to_date(echo):
     """
     Everything up-to-date should be printed.
     """
-    sync(set(), set())
+    sync(set(), set(), verbose=True)
     echo.assert_called_once_with('Everything up-to-date')
Repository: wtforms/wtforms
Pull request #233 (2015-12-12 18:34:09)

Add min/max attributes to html5.NumberInput widget
Since HTML5 `input[type=number]` supports [`min`][1]/[`max`][2] attributes.  It is very useful for limiting the possible range of the value.

[1]: https://developer.mozilla.org/en/docs/Web/HTML/Element/Input#attr-min
[2]: https://developer.mozilla.org/en/docs/Web/HTML/Element/Input#attr-max


Patch:
diff --git a/wtforms/widgets/html5.py b/wtforms/widgets/html5.py
index 011ae9f..c333d00 100644
--- a/wtforms/widgets/html5.py
+++ b/wtforms/widgets/html5.py
@@ -87,12 +87,18 @@ class NumberInput(Input):
     """
     input_type = 'number'
 
-    def __init__(self, step=None):
+    def __init__(self, step=None, min=None, max=None):
         self.step = step
+        self.min = min
+        self.max = max
 
     def __call__(self, field, **kwargs):
         if self.step is not None:
             kwargs.setdefault('step', self.step)
+        if self.min is not None:
+            kwargs.setdefault('min', self.min)
+        if self.max is not None:
+            kwargs.setdefault('max', self.max)
         return super(NumberInput, self).__call__(field, **kwargs)
 
 


Test patch:
diff --git a/tests/widgets.py b/tests/widgets.py
index 16ff47d..ef57817 100644
--- a/tests/widgets.py
+++ b/tests/widgets.py
@@ -144,6 +144,12 @@ class HTML5Test(TestCase):
         self.assertEqual(i1(self.field), '<input id="id" name="bar" step="any" type="number" value="42">')
         i2 = html5.NumberInput(step=2)
         self.assertEqual(i2(self.field, step=3), '<input id="id" name="bar" step="3" type="number" value="42">')
+        i3 = html5.NumberInput(min=10)
+        self.assertEqual(i3(self.field), '<input id="id" min="10" name="bar" type="number" value="42">')
+        self.assertEqual(i3(self.field, min=5), '<input id="id" min="5" name="bar" type="number" value="42">')
+        i4 = html5.NumberInput(max=100)
+        self.assertEqual(i4(self.field), '<input id="id" max="100" name="bar" type="number" value="42">')
+        self.assertEqual(i4(self.field, max=50), '<input id="id" max="50" name="bar" type="number" value="42">')
 
     def test_range(self):
         i1 = html5.RangeInput(step='any')
Repository: wtforms/wtforms
Pull request #248 (2016-01-28 20:48:57)

hyphenate all data-attribute underscores
data-x-y is a much more commonly used naming scheme than data-x_y.  Popular frameworks such as [Bootstrap contains data-x-y attributes](http://getbootstrap.com/javascript/#buttons-methods) as does [Foundation](http://foundation.zurb.com/sites/docs/javascript.html) and [uikit](http://getuikit.com/docs/lightbox.html).  

As mentioned in the [issue comments](https://github.com/wtforms/wtforms/issues/48)— the spec only mentions `data-*` but its clear from just hitting Google with `data- attributes html` that all the top examples show multiple hyphenated usage, so in this case I think there's a greater win in building towards the common convention rather then the spec as stated.


Patch:
diff --git a/wtforms/widgets/core.py b/wtforms/widgets/core.py
index 8d2594c..7617744 100644
--- a/wtforms/widgets/core.py
+++ b/wtforms/widgets/core.py
@@ -44,7 +44,7 @@ def html_params(**kwargs):
         if k in ('class_', 'class__', 'for_'):
             k = k[:-1]
         elif k.startswith('data_'):
-            k = k.replace('_', '-', 1)
+            k = k.replace('_', '-')
         if v is True:
             params.append(k)
         elif v is False:


Test patch:
diff --git a/tests/widgets.py b/tests/widgets.py
index 0432d8f..7a4888b 100644
--- a/tests/widgets.py
+++ b/tests/widgets.py
@@ -32,7 +32,7 @@ class HTMLParamsTest(TestCase):
 
     def test_data_prefix(self):
         self.assertEqual(html_params(data_foo=22), 'data-foo="22"')
-        self.assertEqual(html_params(data_foo_bar=1), 'data-foo_bar="1"')
+        self.assertEqual(html_params(data_foo_bar=1), 'data-foo-bar="1"')
 
     def test_quoting(self):
         self.assertEqual(html_params(foo='hi&bye"quot'), 'foo="hi&amp;bye&quot;quot"')
Repository: wtforms/wtforms
Pull request #251 (2016-02-04 10:00:29)

Changing the UUID validator implementation to use uuid instead of regex.
Current implementation uses Regex. Not sure why.
In my project we use uuid.uuid4().hex - string representation without dashes. This validator doesn't accept it.
What if we let the uuid.UUID(strvalue) parse it? This way it can handle both:
'2bc1c94f-0deb-43e9-92a1-4775189ec9f8' and '2bc1c94f0deb43e992a14775189ec9f8' strings.


Patch:
diff --git a/wtforms/validators.py b/wtforms/validators.py
index 900c1fe..12d678a 100644
--- a/wtforms/validators.py
+++ b/wtforms/validators.py
@@ -1,6 +1,7 @@
 from __future__ import unicode_literals
 
 import re
+import uuid
 import warnings
 
 from wtforms.compat import string_types, text_type
@@ -419,7 +420,7 @@ class URL(Regexp):
             raise ValidationError(message)
 
 
-class UUID(Regexp):
+class UUID(object):
     """
     Validates a UUID.
 
@@ -427,15 +428,16 @@ class UUID(Regexp):
         Error message to raise in case of a validation error.
     """
     def __init__(self, message=None):
-        pattern = r'^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$'
-        super(UUID, self).__init__(pattern, message=message)
+        self.message = message
 
     def __call__(self, form, field):
         message = self.message
         if message is None:
             message = field.gettext('Invalid UUID.')
-
-        super(UUID, self).__call__(form, field, message)
+        try:
+            uuid.UUID(field.data)
+        except ValueError:
+            raise ValidationError(message)
 
 
 class AnyOf(object):


Test patch:
diff --git a/tests/validators.py b/tests/validators.py
index 2167050..3efd15d 100644
--- a/tests/validators.py
+++ b/tests/validators.py
@@ -78,6 +78,10 @@ class ValidatorsTest(TestCase):
             UUID()(self.form, DummyField('2bc1c94f-0deb-43e9-92a1-4775189ec9f8')),
             None
         )
+        self.assertEqual(
+            UUID()(self.form, DummyField('2bc1c94f0deb43e992a14775189ec9f8')),
+            None
+        )
         self.assertRaises(ValidationError, UUID(), self.form,
                           DummyField('2bc1c94f-deb-43e9-92a1-4775189ec9f8'))
         self.assertRaises(ValidationError, UUID(), self.form,
Repository: wtforms/wtforms
Pull request #266 (2016-03-21 15:04:24)

Better notification when min and max string length are the same
Sometimes a string of a fixed length is expect in a form. If you use the `Length` validator, and choose the same value for `max` and `min`, this patch makes the error message more sensible: "Field must be exactly 'n' characters long."



Patch:
diff --git a/wtforms/validators.py b/wtforms/validators.py
index 12d678a..280e8f1 100644
--- a/wtforms/validators.py
+++ b/wtforms/validators.py
@@ -100,6 +100,9 @@ class Length(object):
                 elif self.min == -1:
                     message = field.ngettext('Field cannot be longer than %(max)d character.',
                                              'Field cannot be longer than %(max)d characters.', self.max)
+                elif self.min == self.max:
+                    message = field.ngettext('Field must be exactly %(max)d character long.',
+                                             'Field must be exactly %(max)d characters long.', self.max)
                 else:
                     message = field.gettext('Field must be between %(min)d and %(max)d characters long.')
 


Test patch:
diff --git a/tests/validators.py b/tests/validators.py
index 3efd15d..e8a48b2 100644
--- a/tests/validators.py
+++ b/tests/validators.py
@@ -98,6 +98,7 @@ class ValidatorsTest(TestCase):
         self.assertEqual(length(min=6)(self.form, field), None)
         self.assertRaises(ValidationError, length(max=5), self.form, field)
         self.assertEqual(length(max=6)(self.form, field), None)
+        self.assertEqual(length(min=6,max=6)(self.form, field), None)
 
         self.assertRaises(AssertionError, length)
         self.assertRaises(AssertionError, length, min=5, max=2)
@@ -108,6 +109,7 @@ class ValidatorsTest(TestCase):
         self.assertTrue('at least 8' in grab(min=8))
         self.assertTrue('longer than 5' in grab(max=5))
         self.assertTrue('between 2 and 5' in grab(min=2, max=5))
+        self.assertTrue('exactly 5' in grab(min=5, max=5))
 
     def test_required(self):
         self.assertEqual(required()(self.form, DummyField('foobar')), None)
Repository: wtforms/wtforms
Pull request #280 (2016-06-22 18:38:09)

field.process_formdata should still be called if formdata is empty
Some fields will set a default value if their key is not in `formdata`.  However, `process_formdata` is only called if `formdata` is truthy.  This can cause unexpected field data if `formdata` is empty versus if it just didn't contain the field.

~~~python
class F(Form):
    name = StringField()

f = F(MultiDict())
print(f.name.data)  # None

f = F(MultiDict({'language': 'Python'}))
print(f.name.data)  # ''
~~~

This patch explicitly checks if `formdata` is `None` and adds a test for this case.


Patch:
diff --git a/wtforms/fields/core.py b/wtforms/fields/core.py
index 7ef5420..6ea64e1 100644
--- a/wtforms/fields/core.py
+++ b/wtforms/fields/core.py
@@ -280,12 +280,13 @@ class Field(object):
         except ValueError as e:
             self.process_errors.append(e.args[0])
 
-        if formdata:
+        if formdata is not None:
+            if self.name in formdata:
+                self.raw_data = formdata.getlist(self.name)
+            else:
+                self.raw_data = []
+
             try:
-                if self.name in formdata:
-                    self.raw_data = formdata.getlist(self.name)
-                else:
-                    self.raw_data = []
                 self.process_formdata(self.raw_data)
             except ValueError as e:
                 self.process_errors.append(e.args[0])


Test patch:
diff --git a/tests/form.py b/tests/form.py
index ff20bb5..6a3fd3c 100644
--- a/tests/form.py
+++ b/tests/form.py
@@ -203,6 +203,12 @@ class FormTest(TestCase):
         form = self.F(data=data, test='bar')
         self.assertEqual(form.test.data, 'bar')
 
+    def test_empty_formdata(self):
+        """"If formdata is empty, field.process_formdata should still run to handle empty data."""
+
+        self.assertEqual(self.F(DummyPostData({'other': 'other'})).test.data, '')
+        self.assertEqual(self.F(DummyPostData()).test.data, '')
+
 
 class MetaTest(TestCase):
     class F(Form):
Repository: wtforms/wtforms
Pull request #288 (2016-07-21 19:25:55)

fix SelectField: do not coerce None into a string


Patch:
diff --git a/wtforms/fields/core.py b/wtforms/fields/core.py
index 6ea64e1..b90c010 100644
--- a/wtforms/fields/core.py
+++ b/wtforms/fields/core.py
@@ -456,6 +456,10 @@ class SelectField(SelectFieldBase):
 
     def process_data(self, value):
         try:
+            # protect against coercing None,
+            # such as in text_type(None) -> "None"
+            if value is None:
+                raise ValueError()
             self.data = self.coerce(value)
         except (ValueError, TypeError):
             self.data = None


Test patch:
diff --git a/tests/fields.py b/tests/fields.py
index b54833a..aaf6685 100644
--- a/tests/fields.py
+++ b/tests/fields.py
@@ -287,7 +287,7 @@ class SelectFieldTest(TestCase):
         F = make_form(a=SelectField(choices=[('a', 'Foo')]))
         form = F(DummyPostData(a=[]))
         assert not form.validate()
-        self.assertEqual(form.a.data, 'None')
+        self.assertEqual(form.a.data, None)
         self.assertEqual(len(form.a.errors), 1)
         self.assertEqual(form.a.errors[0], 'Not a valid choice')
 
@@ -367,7 +367,7 @@ class RadioFieldTest(TestCase):
             form.a(),
             '''<ul id="a">'''
             '''<li><input id="a-0" name="a" type="radio" value="True"> <label for="a-0">yes</label></li>'''
-            '''<li><input checked id="a-1" name="a" type="radio" value="False"> <label for="a-1">no</label></li></ul>'''
+            '''<li><input id="a-1" name="a" type="radio" value="False"> <label for="a-1">no</label></li></ul>'''
         )
Repository: wtforms/wtforms
Pull request #302 (2016-10-18 14:42:48)

Choices in `SelectField` objects now handle `HTMLString` correctly.
Proposal for #301 

davidism: You have mistakenly committed your IDE and build files.  Please strip those commits and force push.
sonovice: Thanks, I overlooked it.
davidism: Please add another test to explicitly test `escape_html` in addition to testing it indirectly.

Patch:
diff --git a/wtforms/widgets/core.py b/wtforms/widgets/core.py
index 176e834..ed83038 100644
--- a/wtforms/widgets/core.py
+++ b/wtforms/widgets/core.py
@@ -14,6 +14,24 @@ __all__ = (
 )
 
 
+def escape_html(s, quote=True):
+    """
+    Replace special characters "&", "<" and ">" to HTML-safe sequences.
+
+    If the optional flag quote is true (the default), the quotation mark
+    characters, both double quote (") and single quote (') characters are also
+    translated.
+
+    If a `HTMLString` is provied, it's assumed that whatever you give to
+    escape_html is a string with any unsafe values already escaped.
+    """
+    if hasattr(s, '__html__'):
+        s = s.__html__()
+    else:
+        s = escape(text_type(s), quote=quote)
+    return s
+
+
 def html_params(**kwargs):
     """
     Generate HTML attribute syntax from inputted keyword arguments.
@@ -310,7 +328,7 @@ class Select(object):
         options = dict(kwargs, value=value)
         if selected:
             options['selected'] = True
-        return HTMLString('<option %s>%s</option>' % (html_params(**options), escape(text_type(label), quote=False)))
+        return HTMLString('<option %s>%s</option>' % (html_params(**options), escape_html(label, quote=False)))
 
 
 class Option(object):


Test patch:
diff --git a/tests/widgets.py b/tests/widgets.py
index a8598fa..8b11a68 100644
--- a/tests/widgets.py
+++ b/tests/widgets.py
@@ -21,6 +21,14 @@ class DummyField(object):
     iter_choices = lambda x: iter(x.data)
 
 
+class EscapeHtmlTest(TestCase):
+    def test(self):
+        self.assertEqual(core.escape_html('<i class="bar">foo</i>'), '&lt;i class=&quot;bar&quot;&gt;foo&lt;/i&gt;')
+        self.assertEqual(core.escape_html('<i class="bar">foo</i>', quote=False), '&lt;i class="bar"&gt;foo&lt;/i&gt;')
+        self.assertEqual(core.escape_html(HTMLString('<i class="bar">foo</i>')), '<i class="bar">foo</i>')
+        self.assertEqual(core.escape_html(HTMLString('<i class="bar">foo</i>'), quote=False), '<i class="bar">foo</i>')
+
+
 class HTMLParamsTest(TestCase):
     def test_basic(self):
         self.assertEqual(html_params(foo=9, k='wuuu'), 'foo="9" k="wuuu"')
@@ -138,6 +146,14 @@ class SelectTest(TestCase):
             Select.render_option(True, 'foo', True),
             '<option selected value="True">foo</option>'
         )
+        self.assertEqual(
+            Select.render_option('bar', '<i class="bar"></i>foo', False),
+            '<option value="bar">&lt;i class="bar"&gt;&lt;/i&gt;foo</option>'
+        )
+        self.assertEqual(
+            Select.render_option('bar', HTMLString('<i class="bar"></i>foo'), False),
+            '<option value="bar"><i class="bar"></i>foo</option>'
+        )
 
 
 class HTML5Test(TestCase):
Repository: wtforms/wtforms
Pull request #361 (2017-11-12 23:20:39)

Use HTML5 `required` attribute for required fields
If accepted, this PR will add the HTML5 boolean `required` attribute to all `<input>`, `<textarea>`, and `<select>` fields that have the `required` flag set (e.g., if the `InputRequired` validator is used).


Patch:
diff --git a/wtforms/widgets/core.py b/wtforms/widgets/core.py
index ed83038..aabfefd 100644
--- a/wtforms/widgets/core.py
+++ b/wtforms/widgets/core.py
@@ -179,6 +179,8 @@ class Input(object):
         kwargs.setdefault('type', self.input_type)
         if 'value' not in kwargs:
             kwargs['value'] = field._value()
+        if 'required' not in kwargs and 'required' in getattr(field, 'flags', []):
+            kwargs['required'] = True
         return HTMLString('<input %s>' % self.html_params(name=field.name, **kwargs))
 
 
@@ -289,6 +291,8 @@ class TextArea(object):
     """
     def __call__(self, field, **kwargs):
         kwargs.setdefault('id', field.id)
+        if 'required' not in kwargs and 'required' in getattr(field, 'flags', []):
+            kwargs['required'] = True
         return HTMLString('<textarea %s>%s</textarea>' % (
             html_params(name=field.name, **kwargs),
             escape(text_type(field._value()), quote=False)
@@ -313,6 +317,8 @@ class Select(object):
         kwargs.setdefault('id', field.id)
         if self.multiple:
             kwargs['multiple'] = True
+        if 'required' not in kwargs and 'required' in getattr(field, 'flags', []):
+            kwargs['required'] = True
         html = ['<select %s>' % html_params(name=field.name, **kwargs)]
         for val, label, selected in field.iter_choices():
             html.append(self.render_option(val, label, selected))


Test patch:
diff --git a/tests/fields.py b/tests/fields.py
index 7b92015..1429d8e 100644
--- a/tests/fields.py
+++ b/tests/fields.py
@@ -136,6 +136,7 @@ class FiltersTest(TestCase):
 class FieldTest(TestCase):
     class F(Form):
         a = StringField(default='hello', render_kw={'readonly': True, 'foo': u'bar'})
+        b = StringField(validators=[validators.InputRequired()])
 
     def setUp(self):
         self.field = self.F().a
@@ -204,6 +205,10 @@ class FieldTest(TestCase):
         self.assertEqual(f2.items.choices, [('b', 'b')])
         self.assertTrue(f1.items.choices is not f2.items.choices)
 
+    def test_required_flag(self):
+        form = self.F()
+        self.assertEqual(form.b(), u'<input id="b" name="b" required type="text" value="">')
+
 
 class PrePostTestField(StringField):
     def pre_validate(self, form):
@@ -684,7 +689,7 @@ class FormFieldTest(TestCase):
         self.assertEqual(
             self.F1().a(),
             '''<table id="a">'''
-            '''<tr><th><label for="a-a">A</label></th><td><input id="a-a" name="a-a" type="text" value=""></td></tr>'''
+            '''<tr><th><label for="a-a">A</label></th><td><input id="a-a" name="a-a" required type="text" value=""></td></tr>'''
             '''<tr><th><label for="a-b">B</label></th><td><input id="a-b" name="a-b" type="text" value=""></td></tr>'''
             '''</table>'''
         )