Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove asgiref from minimal requirements #1460

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def get_packages(package):
env_marker_below_38 = "python_version < '3.8'"

minimal_requirements = [
"asgiref>=3.4.0",
"click>=7.0",
"h11>=0.8",
"typing-extensions;" + env_marker_below_38,
]


extra_requirements = [
"asgiref>=3.4.0",
"websockets>=10.0",
"httptools>=0.4.0",
"uvloop>=0.14.0,!=0.15.0,!=0.15.1; " + env_marker_cpython,
Expand Down
8 changes: 6 additions & 2 deletions tests/middleware/test_proxy_headers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from typing import List, Union
from __future__ import annotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this __future__ is in somewhat of a limbo, I would be reluctant to merge it.


from typing import TYPE_CHECKING, List, Union

import httpx
import pytest
from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope

from tests.response import Response
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware

if TYPE_CHECKING:
from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope


async def app(
scope: Scope,
Expand Down
21 changes: 15 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import logging
import os
Expand All @@ -7,14 +9,8 @@
from pathlib import Path
from unittest.mock import MagicMock

if sys.version_info < (3, 8): # pragma: py-gte-38
from typing_extensions import Literal
else: # pragma: py-lt-38
from typing import Literal

import pytest
import yaml
from asgiref.typing import ASGIApplication, ASGIReceiveCallable, ASGISendCallable, Scope
from pytest_mock import MockerFixture

from tests.utils import as_cwd
Expand All @@ -25,6 +21,19 @@
from uvicorn.middleware.wsgi import WSGIMiddleware
from uvicorn.protocols.http.h11_impl import H11Protocol

if sys.version_info < (3, 8): # pragma: py-gte-38
from typing_extensions import Literal
else: # pragma: py-lt-38
from typing import Literal

if typing.TYPE_CHECKING:
from asgiref.typing import (
ASGIApplication,
ASGIReceiveCallable,
ASGISendCallable,
Scope,
)


@pytest.fixture
def mocked_logging_config_module(mocker: MockerFixture) -> MagicMock:
Expand Down
20 changes: 17 additions & 3 deletions uvicorn/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import asyncio
import inspect
import json
Expand All @@ -8,7 +10,19 @@
import ssl
import sys
from pathlib import Path
from typing import Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union
from typing import (
TYPE_CHECKING,
Awaitable,
Callable,
Dict,
List,
Optional,
Tuple,
Type,
Union,
)

import click

from uvicorn._logging import TRACE_LOG_LEVEL

Expand All @@ -17,8 +31,8 @@
else: # pragma: py-lt-38
from typing import Literal

import click
from asgiref.typing import ASGIApplication
if TYPE_CHECKING:
from asgiref.typing import ASGIApplication

try:
import yaml
Expand Down
6 changes: 5 additions & 1 deletion uvicorn/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging
import os
import platform
Expand All @@ -6,7 +8,6 @@
import typing

import click
from asgiref.typing import ASGIApplication

import uvicorn
from uvicorn.config import (
Expand All @@ -23,6 +24,9 @@
from uvicorn.server import Server, ServerState # noqa: F401 # Used to be defined here.
from uvicorn.supervisors import ChangeReload, Multiprocess

if typing.TYPE_CHECKING:
from asgiref.typing import ASGIApplication

LEVEL_CHOICES = click.Choice(list(LOG_LEVELS.keys()))
HTTP_CHOICES = click.Choice(list(HTTP_PROTOCOLS.keys()))
WS_CHOICES = click.Choice(list(WS_PROTOCOLS.keys()))
Expand Down
17 changes: 11 additions & 6 deletions uvicorn/middleware/asgi2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from asgiref.typing import (
ASGI2Application,
ASGIReceiveCallable,
ASGISendCallable,
Scope,
)
from __future__ import annotations

import typing

if typing.TYPE_CHECKING:
from asgiref.typing import (
ASGI2Application,
ASGIReceiveCallable,
ASGISendCallable,
Scope,
)
Comment on lines +5 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite a bit of boilerplate that we'll have to have in every module



class ASGI2Middleware:
Expand Down
25 changes: 14 additions & 11 deletions uvicorn/middleware/debug.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from __future__ import annotations

import html
import traceback
from typing import Union

from asgiref.typing import (
ASGI3Application,
ASGIReceiveCallable,
ASGISendCallable,
ASGISendEvent,
HTTPResponseBodyEvent,
HTTPResponseStartEvent,
WWWScope,
)
from typing import TYPE_CHECKING, Union

if TYPE_CHECKING:
from asgiref.typing import (
ASGI3Application,
ASGIReceiveCallable,
ASGISendCallable,
ASGISendEvent,
HTTPResponseBodyEvent,
HTTPResponseStartEvent,
WWWScope,
)


class HTMLResponse:
Expand Down
23 changes: 13 additions & 10 deletions uvicorn/middleware/message_logger.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import logging
from typing import Any
from __future__ import annotations

from asgiref.typing import (
ASGI3Application,
ASGIReceiveCallable,
ASGIReceiveEvent,
ASGISendCallable,
ASGISendEvent,
WWWScope,
)
import logging
from typing import TYPE_CHECKING, Any

from uvicorn._logging import TRACE_LOG_LEVEL

if TYPE_CHECKING:
from asgiref.typing import (
ASGI3Application,
ASGIReceiveCallable,
ASGIReceiveEvent,
ASGISendCallable,
ASGISendEvent,
WWWScope,
)

PLACEHOLDER_FORMAT = {
"body": "<{length} bytes>",
"bytes": "<{length} bytes>",
Expand Down
23 changes: 13 additions & 10 deletions uvicorn/middleware/proxy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#Proxies
"""
from typing import List, Optional, Tuple, Union, cast
from __future__ import annotations

from asgiref.typing import (
ASGI3Application,
ASGIReceiveCallable,
ASGISendCallable,
HTTPScope,
Scope,
WebSocketScope,
)
from typing import TYPE_CHECKING, List, Optional, Tuple, Union, cast

if TYPE_CHECKING:
from asgiref.typing import (
ASGI3Application,
ASGIReceiveCallable,
ASGISendCallable,
HTTPScope,
Scope,
WebSocketScope,
)


class ProxyHeadersMiddleware:
Expand Down Expand Up @@ -47,7 +50,7 @@ async def __call__(
self, scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable
) -> None:
if scope["type"] in ("http", "websocket"):
scope = cast(Union[HTTPScope, WebSocketScope], scope)
scope = cast(Union["HTTPScope", "WebSocketScope"], scope)
client_addr: Optional[Tuple[str, int]] = scope.get("client")
client_host = client_addr[0] if client_addr else None

Expand Down
27 changes: 15 additions & 12 deletions uvicorn/middleware/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
from __future__ import annotations

import asyncio
import concurrent.futures
import io
import sys
from collections import deque
from typing import Deque, Iterable, Optional, Tuple

from asgiref.typing import (
ASGIReceiveCallable,
ASGIReceiveEvent,
ASGISendCallable,
ASGISendEvent,
HTTPRequestEvent,
HTTPResponseBodyEvent,
HTTPResponseStartEvent,
HTTPScope,
)
from typing import TYPE_CHECKING, Deque, Iterable, Optional, Tuple

from uvicorn._types import Environ, ExcInfo, StartResponse, WSGIApp

if TYPE_CHECKING:
from asgiref.typing import (
ASGIReceiveCallable,
ASGIReceiveEvent,
ASGISendCallable,
ASGISendEvent,
HTTPRequestEvent,
HTTPResponseBodyEvent,
HTTPResponseStartEvent,
HTTPScope,
)


def build_environ(
scope: HTTPScope, message: ASGIReceiveEvent, body: io.BytesIO
Expand Down
18 changes: 11 additions & 7 deletions uvicorn/protocols/http/flow_control.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

import asyncio
import typing

from asgiref.typing import (
ASGIReceiveCallable,
ASGISendCallable,
HTTPResponseBodyEvent,
HTTPResponseStartEvent,
Scope,
)
if typing.TYPE_CHECKING:
from asgiref.typing import (
ASGIReceiveCallable,
ASGISendCallable,
HTTPResponseBodyEvent,
HTTPResponseStartEvent,
Scope,
)

CLOSE_HEADER = (b"connection", b"close")

Expand Down