nebius/SWE-bench-extra huggingface dataset:
Repository: grktsh/falcon-oas

Issue:
Support nullable enum
Same as #3, just for `enum`.

Comments:

Patch:
diff --git a/src/falcon_oas/oas/schema/validators.py b/src/falcon_oas/oas/schema/validators.py
index e853bb4..a8b09fd 100644
--- a/src/falcon_oas/oas/schema/validators.py
+++ b/src/falcon_oas/oas/schema/validators.py
@@ -19,7 +19,20 @@ def _type_validator(validator, types, instance, schema):
         yield error
 
 
-_Validator = validators.extend(Draft4Validator, {'type': _type_validator})
+_enum_draft4_validator = Draft4Validator.VALIDATORS['enum']
+
+
+def _enum_validator(validator, enums, instance, schema):
+    if instance is None and schema.get('nullable'):
+        return
+
+    for error in _enum_draft4_validator(validator, enums, instance, schema):
+        yield error
+
+
+_Validator = validators.extend(
+    Draft4Validator, {'type': _type_validator, 'enum': _enum_validator}
+)
 
 
 class SchemaValidator(object):


Test patch:
diff --git a/tests/oas/schema/test_unmarshalers.py b/tests/oas/schema/test_unmarshalers.py
index 4783e5f..f94bde3 100644
--- a/tests/oas/schema/test_unmarshalers.py
+++ b/tests/oas/schema/test_unmarshalers.py
@@ -56,6 +56,13 @@ def test_unmarshal_primitive_without_formats():
     assert unmarshaled == instance
 
 
+def test_unmarshal_primitive_enum():
+    schema = {'type': 'string', 'enum': ['a', 'b']}
+    instance = 'a'
+    unmarshaled = SchemaUnmarshaler().unmarshal(instance, schema)
+    assert unmarshaled == 'a'
+
+
 def test_unmarshal_array():
     schema = {'type': 'array', 'items': {'type': 'string', 'format': 'date'}}
     instance = ['2018-01-02', '2018-02-03', '2018-03-04']
@@ -164,6 +171,7 @@ def test_unmarshal_one_of_or_any_of(schema_type):
         {'type': 'array', 'nullable': True},
         {'type': 'object', 'nullable': True},
         {'type': 'string', 'format': 'date', 'nullable': True},
+        {'type': 'string', 'enum': ['a', 'b'], 'nullable': True},
     ],
 )
 def test_unmarshal_nullable(schema):
diff --git a/tests/oas/schema/test_validators.py b/tests/oas/schema/test_validators.py
index f0666d1..4a9bce8 100644
--- a/tests/oas/schema/test_validators.py
+++ b/tests/oas/schema/test_validators.py
@@ -37,6 +37,18 @@ def test_validate_error(validator):
     assert exc_info.value.errors[0].message == message
 
 
+def test_validate_enum_error(validator):
+    schema = {'type': str('string'), 'enum': [str('a'), str('b')]}
+    instance = str('c')
+    message = "'c' is not one of ['a', 'b']"
+
+    with pytest.raises(ValidationError) as exc_info:
+        validator.validate(instance, schema)
+
+    assert len(exc_info.value.errors) == 1
+    assert exc_info.value.errors[0].message == message
+
+
 def test_validate_format_string(validator):
     schema = {'type': 'string', 'format': 'date'}
     instance = '2018-01-02'
Repository: gvalkov/tornado-http-auth

Issue:
authenticate_user method raises binascii.Error when provided auth is not base64
`authenticate_user` method raises uncontrolled exception when the provided Authorization header is not base64. To reproduce the issue:

```
curl -i \
    -H 'Accept:application/json' \
    -H 'Authorization:Basic not_a_base64_string' \
    http://localhost:8000/protected
```



Comments:

Patch:
diff --git a/tornado_http_auth.py b/tornado_http_auth.py
index 2c6efbb..cbe74c8 100644
--- a/tornado_http_auth.py
+++ b/tornado_http_auth.py
@@ -209,8 +209,11 @@ class BasicAuthMixin(object):
             raise self.SendChallenge()
 
         auth_data = auth_header.split(None, 1)[-1]
-        auth_data = base64.b64decode(auth_data).decode('ascii')
-        username, password = auth_data.split(':', 1)
+        try:
+            auth_data = base64.b64decode(auth_data, validate=True).decode('ascii')
+            username, password = auth_data.split(':', 1)
+        except (UnicodeDecodeError, binascii.Error):
+            raise self.SendChallenge()
 
         challenge = check_credentials_func(username)
         if not challenge:


Test patch:
diff --git a/tests/test_functional.py b/tests/test_functional.py
index d03680b..ca2a817 100644
--- a/tests/test_functional.py
+++ b/tests/test_functional.py
@@ -40,9 +40,14 @@ class AuthTest(AsyncHTTPTestCase):
         res = self.fetch('/basic')
         self.assertEqual(res.code, 401)
 
+        res = self.fetch('/basic', headers={'Authorization': 'Basic foo bar'})
+        self.assertEqual(res.code, 401)
+
         auth = '%s:%s' % ('user1', 'pass1')
         auth = b64encode(auth.encode('ascii'))
-        hdr = {'Authorization': 'Basic %s' % auth.decode('utf8')}
-        res = self.fetch('/basic', headers=hdr)
-        self.assertEqual(res.code, 200)
 
+        res = self.fetch('/basic', headers={'Authorization': 'Basic ___%s' % auth.decode('utf8')})
+        self.assertEqual(res.code, 401)
+
+        res = self.fetch('/basic', headers={'Authorization': 'Basic %s' % auth.decode('utf8')})
+        self.assertEqual(res.code, 200)
Repository: haddocking/arctic3d

Issue:
handle duplicate labels in arctic3d-localise plots
when we shorten labels we may have duplicate labels that should be removed from the plot

Comments:

Patch:
diff --git a/src/arctic3d/modules/output.py b/src/arctic3d/modules/output.py
index 7f75c08..1695c82 100644
--- a/src/arctic3d/modules/output.py
+++ b/src/arctic3d/modules/output.py
@@ -503,13 +503,54 @@ def create_barplot(cluster, sorted_dict, max_labels=70):
     return
 
 
+def remove_duplicate_labels(labels, values):
+    """
+    Remove duplicate labels.
+
+    Parameters
+    ----------
+    labels : list
+        list of labels
+    values : list
+        list of values
+
+    Returns
+    -------
+    new_labels : list
+        list of labels without duplicates
+    new_values : list
+        list of values without duplicates
+    """
+    new_labels, new_values = [], []
+    for n in range(len(labels)):
+        if labels[n] not in new_labels:
+            new_labels.append(labels[n])
+            new_values.append(values[n])
+        else:
+            log.info(f"Detected duplicate label {labels[n]}.")
+    return new_labels, new_values
+
+
 def create_barplotly(cluster, sorted_dict, format, scale, max_labels=25):
     """
     Create horizontal barplot using plotly.
 
+    Parameters
+    ----------
+    cluster : int or str
+        cluster ID
+    sorted_dict : dict
+        dictionary of sorted entries
+    format : str
+        format of the output figure
+    scale : float
+        scale of the output figure
+    max_labels : int
+        maximum number of labels to include
     """
-    labels = shorten_labels(list(sorted_dict.keys())[-max_labels:])
-    values = list(sorted_dict.values())[-max_labels:]
+    tmp_labels = shorten_labels(list(sorted_dict.keys())[-max_labels:])
+    tmp_values = list(sorted_dict.values())[-max_labels:]
+    labels, values = remove_duplicate_labels(tmp_labels, tmp_values)
     fig = go.Figure(go.Bar(x=values, y=labels, orientation="h"))
     fig_fname = f"cluster_{cluster}.html"
     fig.write_html(fig_fname)


Test patch:
diff --git a/tests/test_output.py b/tests/test_output.py
index 497f843..9d637d9 100644
--- a/tests/test_output.py
+++ b/tests/test_output.py
@@ -7,6 +7,7 @@ from arctic3d.modules.output import (
     create_output_folder,
     output_pdb,
     read_residues_probs,
+    remove_duplicate_labels,
     setup_output_folder,
     shorten_labels,
     write_dict,
@@ -192,3 +193,14 @@ def test_shorten_labels(example_B_labels):
         "positive regulation of transcription by RNA polymerase...",
     ]
     assert exp_shortened_labels == obs_shortened_labels
+
+
+def test_remove_duplicate_labels():
+    """Test remove_duplicate_labels."""
+    tmp_labels = ["Polymerase...", "Polymerase...", "Polymerase..."]
+    tmp_values = [2, 3, 1]
+    exp_labels = ["Polymerase..."]
+    exp_values = [2]
+    obs_labels, obs_values = remove_duplicate_labels(tmp_labels, tmp_values)
+    assert exp_labels == obs_labels
+    assert exp_values == obs_values