From b9adf7790293bf675f0e0caaccba0aa01f2b1d91 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 1 May 2022 21:48:58 +0300 Subject: [PATCH] Remove compat code for Python <= 3.6 --- setup.py | 1 - starlette/routing.py | 7 +------ starlette/status.py | 4 +--- tests/test_applications.py | 7 +------ tests/test_testclient.py | 11 ++--------- 5 files changed, 5 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index e5447f981..1597ef452 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import os import re diff --git a/starlette/routing.py b/starlette/routing.py index 7b7dc9b74..67f12e311 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -3,11 +3,11 @@ 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.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): """ diff --git a/starlette/status.py b/starlette/status.py index f350d448f..1689328a4 100644 --- a/starlette/status.py +++ b/starlette/status.py @@ -5,7 +5,6 @@ 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}'") diff --git a/tests/test_applications.py b/tests/test_applications.py index 62ddd7602..0d0ede571 100644 --- a/tests/test_applications.py +++ b/tests/test_applications.py @@ -1,5 +1,5 @@ import os -import sys +from contextlib import asynccontextmanager import pytest @@ -12,11 +12,6 @@ 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) diff --git a/tests/test_testclient.py b/tests/test_testclient.py index 22f0b3880..c9c7f33ca 100644 --- a/tests/test_testclient.py +++ b/tests/test_testclient.py @@ -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.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"})