Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove compat code for Python <= 3.6 #1616

Merged
merged 2 commits into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion setup.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import re
Expand Down
7 changes: 1 addition & 6 deletions starlette/routing.py
Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down
4 changes: 1 addition & 3 deletions starlette/status.py
Expand Up @@ -5,7 +5,6 @@

And RFC 2324 - https://tools.ietf.org/html/rfc2324
"""
import sys
import warnings
from typing import List

Expand Down Expand Up @@ -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}'")
Expand Down
7 changes: 1 addition & 6 deletions tests/test_applications.py
@@ -1,5 +1,5 @@
import os
import sys
from contextlib import asynccontextmanager

import pytest

Expand All @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions 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
Expand All @@ -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"})
Expand Down