Add more py37 typing hacks

This commit is contained in:
Adam Hopkins 2021-02-22 14:08:04 +02:00
parent 3a45d3291b
commit 9c48c7d39b
4 changed files with 3 additions and 46 deletions

View File

@ -1,21 +0,0 @@
import sys
from typing import Union
if sys.version_info < (3, 8):
from asyncio import BaseTransport
from sanic.models.asgi import MockTransport
TransportProtocol = Union[MockTransport, BaseTransport]
else:
# Protocol is a 3.8+ feature
from typing import Protocol
class TransportProtocol(Protocol):
def get_protocol(self):
...
def get_extra_info(self, info: str) -> Union[str, bool, None]:
...

View File

@ -38,7 +38,7 @@ from sanic.headers import (
parse_xforwarded,
)
from sanic.log import error_logger, logger
from sanic.models.transport import TransportProtocol
from sanic.models.protocol_types import TransportProtocol
from sanic.response import BaseHTTPResponse, HTTPResponse

View File

@ -10,7 +10,6 @@ from typing import (
Dict,
Iterator,
Optional,
Protocol,
Tuple,
Union,
)
@ -21,6 +20,7 @@ from sanic.compat import Header, open_async
from sanic.cookies import CookieJar
from sanic.helpers import has_message_body, remove_entity_headers
from sanic.http import Http
from sanic.models.protocol_types import HTMLProtocol, Range
try:
@ -33,28 +33,6 @@ except ImportError:
json_dumps = partial(dumps, separators=(",", ":"))
class HTMLProtocol(Protocol):
def __html__(self) -> AnyStr:
...
def _repr_html_(self) -> AnyStr:
...
class Range(Protocol):
def start(self) -> int:
...
def end(self) -> int:
...
def size(self) -> int:
...
def total(self) -> int:
...
class BaseHTTPResponse:
"""
The base class for all HTTP Responses

View File

@ -39,7 +39,7 @@ from sanic.config import Config
from sanic.exceptions import RequestTimeout, ServiceUnavailable
from sanic.http import Http, Stage
from sanic.log import logger
from sanic.models.transport import TransportProtocol
from sanic.models.protocol_types import TransportProtocol
from sanic.request import Request