use typing.Union for pre-3.10 compat (#1626)
This commit is contained in:
@@ -198,7 +198,7 @@ def gzip(func):
|
||||
return inner
|
||||
|
||||
|
||||
def apply_gzip(headers: dict, content: str | bytes) -> str | bytes:
|
||||
def apply_gzip(headers: dict, content: Union[str, bytes]) -> Union[str, bytes]:
|
||||
"""
|
||||
Compress content if requested in header.
|
||||
"""
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
"""Integration module for Django"""
|
||||
|
||||
from typing import Tuple, Dict, Mapping, Optional
|
||||
from typing import Tuple, Dict, Mapping, Optional, Union
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
@@ -562,7 +562,7 @@ def execute_from_django(api_function, request: HttpRequest, *args,
|
||||
api_ = API(settings.PYGEOAPI_CONFIG, settings.OPENAPI_DOCUMENT)
|
||||
|
||||
api_request = APIRequest.from_django(request, api_.locales)
|
||||
content: str | bytes
|
||||
content: Union[str, bytes]
|
||||
if not skip_valid_check and not api_request.is_valid():
|
||||
headers, status, content = api_.get_format_exception(api_request)
|
||||
else:
|
||||
@@ -575,7 +575,7 @@ def execute_from_django(api_function, request: HttpRequest, *args,
|
||||
|
||||
# TODO: inline this to execute_from_django after refactoring
|
||||
def _to_django_response(headers: Mapping, status_code: int,
|
||||
content: str | bytes) -> HttpResponse:
|
||||
content: Union[str, bytes]) -> HttpResponse:
|
||||
"""Convert API payload to a django response"""
|
||||
|
||||
response = HttpResponse(content, status=status_code)
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
"""Flask module providing the route paths to the api"""
|
||||
|
||||
import os
|
||||
from typing import Union
|
||||
|
||||
import click
|
||||
|
||||
from flask import (Flask, Blueprint, make_response, request,
|
||||
send_from_directory, Response, Request)
|
||||
|
||||
@@ -152,7 +152,7 @@ def execute_from_flask(api_function, request: Request, *args,
|
||||
|
||||
api_request = APIRequest.from_flask(request, api_.locales)
|
||||
|
||||
content: str | bytes
|
||||
content: Union[str, bytes]
|
||||
|
||||
if not skip_valid_check and not api_request.is_valid():
|
||||
headers, status, content = api_.get_format_exception(api_request)
|
||||
|
||||
@@ -38,7 +38,6 @@ from typing import Callable, Union
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from starlette.routing import Route, Mount
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from starlette.applications import Starlette
|
||||
@@ -142,7 +141,7 @@ def _to_response(headers, status, content):
|
||||
async def execute_from_starlette(api_function, request: Request, *args,
|
||||
skip_valid_check=False) -> Response:
|
||||
api_request = await APIRequest.from_starlette(request, api_.locales)
|
||||
content: str | bytes
|
||||
content: Union[str, bytes]
|
||||
if not skip_valid_check and not api_request.is_valid():
|
||||
headers, status, content = api_.get_format_exception(api_request)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user