Remove compat code for Python < 3.7 (#1616)

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
Hugo van Kemenade 2022-05-01 23:03:41 +03:00 committed by GitHub
parent 88de894369
commit 589df78616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 25 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re

View File

@ -3,11 +3,11 @@ import contextlib
import functools
import inspect
import re
import sys
import traceback
import types
import typing
import warnings
from contextlib import asynccontextmanager
from enum import Enum
from starlette.concurrency import run_in_threadpool
@ -19,11 +19,6 @@ from starlette.responses import PlainTextResponse, RedirectResponse
from starlette.types import ASGIApp, Receive, Scope, Send
from starlette.websockets import WebSocket, WebSocketClose
if sys.version_info >= (3, 7):
from contextlib import asynccontextmanager # pragma: no cover
else:
from contextlib2 import asynccontextmanager # pragma: no cover
class NoMatchFound(Exception):
"""

View File

@ -5,7 +5,6 @@ https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
And RFC 2324 - https://tools.ietf.org/html/rfc2324
"""
import sys
import warnings
from typing import List
@ -187,11 +186,10 @@ def __getattr__(name: str) -> int:
}
deprecated = __deprecated__.get(name)
if deprecated:
stacklevel = 3 if sys.version_info >= (3, 7) else 4
warnings.warn(
f"'{name}' is deprecated. Use '{deprecation_changes[name]}' instead.",
category=DeprecationWarning,
stacklevel=stacklevel,
stacklevel=3,
)
return deprecated
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

View File

@ -1,5 +1,5 @@
import os
import sys
from contextlib import asynccontextmanager
import pytest
@ -12,11 +12,6 @@ from starlette.responses import JSONResponse, PlainTextResponse
from starlette.routing import Host, Mount, Route, Router, WebSocketRoute
from starlette.staticfiles import StaticFiles
if sys.version_info >= (3, 7):
from contextlib import asynccontextmanager # pragma: no cover
else:
from contextlib2 import asynccontextmanager # pragma: no cover
async def error_500(request, exc):
return JSONResponse({"detail": "Server Error"}, status_code=500)

View File

@ -1,6 +1,6 @@
import asyncio
import itertools
import sys
from asyncio import current_task as asyncio_current_task
from contextlib import asynccontextmanager
import anyio
import pytest
@ -13,13 +13,6 @@ from starlette.responses import JSONResponse
from starlette.routing import Route
from starlette.websockets import WebSocket, WebSocketDisconnect
if sys.version_info >= (3, 7): # pragma: no cover
from asyncio import current_task as asyncio_current_task
from contextlib import asynccontextmanager
else: # pragma: no cover
asyncio_current_task = asyncio.Task.current_task
from contextlib2 import asynccontextmanager
def mock_service_endpoint(request):
return JSONResponse({"mock": "example"})