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

Drop python 3.8 #522

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
python-version: [ 3.9, "3.10", "3.11", "3.12", "3.13"]
runs-on: windows-latest
if: github.event_name == 'pull_request' || github.event_name == 'push'

Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}

steps:
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
Expand Down
8 changes: 1 addition & 7 deletions blacksheep/asgi.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import sys
from typing import List, Tuple

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict
from typing import List, Tuple, TypedDict

class ASGIScopeInterface(TypedDict):
type: str
Expand Down
17 changes: 0 additions & 17 deletions blacksheep/server/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,6 @@ def __init__(self, parameter_name, route):
Tuple[UUID],
}

try:
# Note: try catch here is to support Python 3.8
# it can be removed when support for Python 3.8 is dropped
_types_handled_with_query |= {
list[str],
list[int],
list[float],
list[bool],
list[UUID],
tuple[str],
tuple[int],
tuple[float],
tuple[bool],
}
except TypeError:
pass


def _check_union(
parameter: ParamInfo, annotation: Any, method: Callable[..., Any]
Expand Down
13 changes: 4 additions & 9 deletions blacksheep/server/openapi/v3.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import collections.abc as collections_abc
import inspect
import sys
import warnings
from abc import ABC, abstractmethod
from dataclasses import dataclass, fields, is_dataclass
from datetime import date, datetime
from enum import Enum, IntEnum
from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union

if sys.version_info >= (3, 9):
from typing import _AnnotatedAlias as AnnotatedAlias

from typing import _AnnotatedAlias as AnnotatedAlias
from typing import _GenericAlias as GenericAlias
from typing import get_type_hints
from uuid import UUID
Expand Down Expand Up @@ -658,10 +654,9 @@ def _get_schema_by_type(
if stored_ref: # pragma: no cover
return stored_ref

if sys.version_info >= (3, 9):
if isinstance(object_type, AnnotatedAlias):
# Replace Annotated object type with the original type
object_type = getattr(object_type, "__origin__")
if isinstance(object_type, AnnotatedAlias):
# Replace Annotated object type with the original type
object_type = getattr(object_type, "__origin__")

if self._can_handle_class_type(object_type):
return self._get_schema_for_class(object_type)
Expand Down
13 changes: 3 additions & 10 deletions blacksheep/server/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@
package.
"""

try:
from importlib.resources import files
from importlib.resources import files

def get_resource_file_path(anchor, file_name: str) -> str:
return str(files(anchor) / file_name)

except ImportError:
# Python 3.8
import pkg_resources

def get_resource_file_path(anchor, file_name: str) -> str:
return pkg_resources.resource_filename(anchor, file_name)
def get_resource_file_path(anchor, file_name: str) -> str:
return str(files(anchor) / file_name)


def get_resource_file_content(file_name: str) -> str:
Expand Down
9 changes: 2 additions & 7 deletions blacksheep/utils/aio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import json
import sys
import urllib.error
import urllib.parse
import urllib.request
Expand Down Expand Up @@ -75,13 +74,9 @@ async def post_form(self, url: str, data: Any) -> Any:
return await self.loop.run_in_executor(None, lambda: post(url, data))


def get_running_loop() -> AbstractEventLoop: # pragma: no cover
def get_running_loop() -> AbstractEventLoop:
try:
if sys.version_info[:2] <= (3, 7):
# For Python 3.6
return asyncio._get_running_loop() or asyncio.get_event_loop()
else:
return asyncio.get_running_loop()
return asyncio.get_running_loop()
except RuntimeError:
# TODO: fix deprecation warning happening in the test suite
# DeprecationWarning: There is no current event loop
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ requires-python = ">=3.7"
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Cython==3.0.11
essentials==1.1.5
essentials-openapi==1.0.9
Flask==3.0.3
gevent==24.2.1
gevent==24.11.1
greenlet==3.1.1
guardpost==1.0.2
h11==0.14.0
Expand Down
45 changes: 21 additions & 24 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from functools import wraps
from typing import Any, Dict, List, Optional, TypeVar
from typing import Annotated, Any, Dict, List, Optional, TypeVar
from uuid import UUID, uuid4

import pytest
Expand Down Expand Up @@ -1512,30 +1512,27 @@ async def home(item: FromJSON[Item]):
assert app.response.status == 204


if sys.version_info >= (3, 9):
from typing import Annotated

@pytest.mark.asyncio
async def test_handler_from_json_annotated_parameter(app):
@app.router.post("/")
async def home(item: Annotated[Item, FromJSON]):
assert item is not None
value = item
assert value.a == "Hello"
assert value.b == "World"
assert value.c == 10
@pytest.mark.asyncio
async def test_handler_from_json_annotated_parameter(app):
@app.router.post("/")
async def home(item: Annotated[Item, FromJSON]):
assert item is not None
value = item
assert value.a == "Hello"
assert value.b == "World"
assert value.c == 10

app.normalize_handlers()
await app(
get_example_scope(
"POST",
"/",
[(b"content-type", b"application/json"), (b"content-length", b"32")],
),
MockReceive([b'{"a":"Hello","b":"World","c":10}']),
MockSend(),
)
assert app.response.status == 204
app.normalize_handlers()
await app(
get_example_scope(
"POST",
"/",
[(b"content-type", b"application/json"), (b"content-length", b"32")],
),
MockReceive([b'{"a":"Hello","b":"World","c":10}']),
MockSend(),
)
assert app.response.status == 204


@pytest.mark.asyncio
Expand Down
Loading
Loading