nebius/SWE-bench-extra huggingface dataset:
Repository: encode/typesystem

Issue:
ValidationError can't be shown with `traceback.print_exc()` in Python 3.6
Consider the following code:

```python
import traceback
import typesystem

try:
    typesystem.Integer().validate("hello")
except typesystem.ValidationError:
    traceback.print_exc()
```

Because of an issue with Python 3.6 discussed in [issue 28803](https://bugs.python.org/issue28603), since `ValidationError` implements `__eq__` but not `__hash__` it is not hashable and `print_exc()` fails to process it correctly.

```
TypeError: unhashable type: 'ValidationError'
```

(Full traceback available [here](https://travis-ci.org/bocadilloproject/bocadillo/jobs/513086149))

Looks like we'd need to implement `ValidationError.__hash__()` to fix this.

Comments:

Patch:
diff --git a/typesystem/base.py b/typesystem/base.py
index bd15068..def115c 100644
--- a/typesystem/base.py
+++ b/typesystem/base.py
@@ -78,6 +78,10 @@ class Message:
             and self.end_position == other.end_position
         )
 
+    def __hash__(self) -> int:
+        ident = (self.code, tuple(self.index))
+        return hash(ident)
+
     def __repr__(self) -> str:
         class_name = self.__class__.__name__
         index_str = f", index={self.index!r}" if self.index else ""
@@ -183,6 +187,10 @@ class BaseError(Mapping, Exception):
     def __eq__(self, other: typing.Any) -> bool:
         return isinstance(other, ValidationError) and self._messages == other._messages
 
+    def __hash__(self) -> int:
+        ident = tuple(hash(m) for m in self._messages)
+        return hash(ident)
+
     def __repr__(self) -> str:
         class_name = self.__class__.__name__
         if len(self._messages) == 1 and not self._messages[0].index:


Test patch:
diff --git a/tests/test_fields.py b/tests/test_fields.py
index b908a66..56f24e6 100644
--- a/tests/test_fields.py
+++ b/tests/test_fields.py
@@ -825,3 +825,9 @@ def test_error_messages_interface():
     validator = Integer()
     value, error = validator.validate_or_error("abc")
     assert error.messages() == [Message(text="Must be a number.", code="type")]
+
+
+def test_validation_error_is_hashable():
+    validator = Integer()
+    _, error = validator.validate_or_error("abc")
+    hash(error)
Repository: encode/uvicorn

Issue:
Uvicorn assumes that `HTTPResponseStartEvent.headers` is a `List`
### Discussed in https://github.com/encode/uvicorn/discussions/1779

<div type='discussions-op-text'>

<sup>Originally posted by **rijenkii** November 27, 2022</sup>
According to the spec and asgiref, `HTTPResponseStartEvent.headers` is `Iterable[Tuple[bytes, bytes]]`.

But, if `http.response.start` is sent like this:
```python
headers: dict
await send({
  "type": "http.response.start",
  "status": status,
  "headers": headers.items(),
})
```

Uvicorn fails with
```
  File ".../uvicorn/protocols/http/h11_impl.py", line 474, in send
    headers = self.default_headers + message_headers
              ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: can only concatenate list (not "dict_items") to list
```

Relevant Uvicorn code: https://github.com/encode/uvicorn/blob/782f17e3855d5f36ce69d55427e74ca7f9b998c5/uvicorn/protocols/http/h11_impl.py#L471-L474

---

Potential fix may just be this:
```python
message_headers = list(message.get("headers", [])) 
```</div>

Comments:

Patch:
diff --git a/uvicorn/protocols/http/h11_impl.py b/uvicorn/protocols/http/h11_impl.py
index 9f6931e..c2764b0 100644
--- a/uvicorn/protocols/http/h11_impl.py
+++ b/uvicorn/protocols/http/h11_impl.py
@@ -468,10 +468,7 @@ class RequestResponseCycle:
             self.waiting_for_100_continue = False
 
             status_code = message["status"]
-            message_headers = cast(
-                List[Tuple[bytes, bytes]], message.get("headers", [])
-            )
-            headers = self.default_headers + message_headers
+            headers = self.default_headers + list(message.get("headers", []))
 
             if CLOSE_HEADER in self.scope["headers"] and CLOSE_HEADER not in headers:
                 headers = headers + [CLOSE_HEADER]


Test patch:
diff --git a/tests/protocols/test_http.py b/tests/protocols/test_http.py
index 79946ad..8db2795 100644
--- a/tests/protocols/test_http.py
+++ b/tests/protocols/test_http.py
@@ -966,3 +966,17 @@ async def test_return_close_header(protocol_cls, close_header: bytes):
     assert b"content-type: text/plain" in protocol.transport.buffer
     assert b"content-length: 12" in protocol.transport.buffer
     assert close_header in protocol.transport.buffer
+
+
+@pytest.mark.anyio
+@pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS)
+async def test_iterator_headers(protocol_cls):
+    async def app(scope, receive, send):
+        headers = iter([(b"x-test-header", b"test value")])
+        await send({"type": "http.response.start", "status": 200, "headers": headers})
+        await send({"type": "http.response.body", "body": b""})
+
+    protocol = get_connected_protocol(app, protocol_cls)
+    protocol.data_received(SIMPLE_GET_REQUEST)
+    await protocol.loop.run_one()
+    assert b"x-test-header: test value" in protocol.transport.buffer