use typing.Union for pre-3.10 compat (#1626)

This commit is contained in:
Tom Kralidis
2024-04-12 16:38:04 -04:00
committed by GitHub
parent a26662e0e4
commit ea2fb87ff5
4 changed files with 7 additions and 8 deletions
+1 -1
View File
@@ -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.
"""
+3 -3
View File
@@ -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)
+2 -2
View File
@@ -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)
+1 -2
View File
@@ -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: