From e1666f5c18eceb5c4f95f5a31ca45c6dd3fa601f Mon Sep 17 00:00:00 2001
From: Paul Brussee
Date: Tue, 10 Jan 2023 21:03:13 +0100
Subject: [PATCH] refactor: ignore type at assignment
---
uvicorn/protocols/http/h11_impl.py | 4 +---
uvicorn/protocols/http/httptools_impl.py | 4 +---
uvicorn/protocols/websockets/websockets_impl.py | 4 +---
uvicorn/protocols/websockets/wsproto_impl.py | 6 ++----
4 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/uvicorn/protocols/http/h11_impl.py b/uvicorn/protocols/http/h11_impl.py
index a2e0f61893..4a70467fc6 100644
--- a/uvicorn/protocols/http/h11_impl.py
+++ b/uvicorn/protocols/http/h11_impl.py
@@ -240,10 +240,8 @@ def handle_events(self) -> None:
"raw_path": raw_path,
"query_string": query_string,
"headers": self.headers,
- "extensions": {},
+ "extensions": ({"tls": self.tls} if self.scheme == "https" else {}),
}
- if self.scheme == "https":
- self.scope["extensions"]["tls"] = self.tls
upgrade = self._get_upgrade()
if upgrade == b"websocket" and self._should_upgrade_to_ws():
diff --git a/uvicorn/protocols/http/httptools_impl.py b/uvicorn/protocols/http/httptools_impl.py
index b85d81afb0..7f3d9eccc0 100644
--- a/uvicorn/protocols/http/httptools_impl.py
+++ b/uvicorn/protocols/http/httptools_impl.py
@@ -255,10 +255,8 @@ def on_message_begin(self) -> None:
"scheme": self.scheme,
"root_path": self.root_path,
"headers": self.headers,
- "extensions": {},
+ "extensions": ({"tls": self.tls} if self.scheme == "https" else {}),
}
- if self.scheme == "https":
- self.scope["extensions"]["tls"] = self.tls
# Parser callbacks
def on_url(self, url: bytes) -> None:
diff --git a/uvicorn/protocols/websockets/websockets_impl.py b/uvicorn/protocols/websockets/websockets_impl.py
index 1335733cd4..9b2970169f 100644
--- a/uvicorn/protocols/websockets/websockets_impl.py
+++ b/uvicorn/protocols/websockets/websockets_impl.py
@@ -208,10 +208,8 @@ async def process_request(
"query_string": query_string.encode("ascii"),
"headers": asgi_headers,
"subprotocols": subprotocols,
- "extensions": {},
+ "extensions": ({"tls": self.tls} if self.scheme == "wss" else {}),
}
- if self.scheme == "wss":
- self.scope["extensions"]["tls"] = self.tls
task = self.loop.create_task(self.run_asgi())
task.add_done_callback(self.on_task_complete)
self.tasks.add(task)
diff --git a/uvicorn/protocols/websockets/wsproto_impl.py b/uvicorn/protocols/websockets/wsproto_impl.py
index ed13b0c9cf..f0c2866073 100644
--- a/uvicorn/protocols/websockets/wsproto_impl.py
+++ b/uvicorn/protocols/websockets/wsproto_impl.py
@@ -178,7 +178,7 @@ def handle_connect(self, event: events.Request) -> None:
headers = [(b"host", event.host.encode())]
headers += [(key.lower(), value) for key, value in event.extra_headers]
raw_path, _, query_string = event.target.partition("?")
- self.scope: "WebSocketScope" = {
+ self.scope: "WebSocketScope" = { # type: ignore[typeddict-item]
"type": "websocket",
"asgi": {"version": self.config.asgi_version, "spec_version": "2.3"},
"http_version": "1.1",
@@ -191,10 +191,8 @@ def handle_connect(self, event: events.Request) -> None:
"query_string": query_string.encode("ascii"),
"headers": headers,
"subprotocols": event.subprotocols,
- "extensions": {},
+ "extensions": ({"tls": self.tls} if self.scheme == "wss" else {}),
}
- if self.scheme == "wss":
- self.scope["extensions"]["tls"] = self.tls
self.queue.put_nowait({"type": "websocket.connect"})
task = self.loop.create_task(self.run_asgi())
task.add_done_callback(self.on_task_complete)