Skip to content

Commit 15b9e57

Browse files
yezz123wu-clan
andauthored
✨ feat: Support PEP563 (#102)
* ✨ add PEP563 support * ✨ update to python >= 3.8 * 🚨 Fix Linting issues * πŸ’š Test `py3.8` & `py3.9` --------- Co-authored-by: wu <[email protected]>
1 parent 1947b22 commit 15b9e57

File tree

12 files changed

+30
-13
lines changed

12 files changed

+30
-13
lines changed

β€Ž.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
timeout-minutes: 30
1414
strategy:
1515
matrix:
16-
python-version: ["3.10", "3.11"]
16+
python-version: ["3.8", "3.9", "3.10", "3.11"]
1717

1818
steps:
1919
- uses: actions/checkout@v3

β€Ž.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# Pycharm
132+
.idea/

β€Žfastapi_class/exception/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
)
66

77
__all__ = [
8-
"FormattedMessageException" "ExceptionAbstract",
8+
"FormattedMessageException",
9+
"ExceptionAbstract",
910
"UNKOWN_SERVER_ERROR_DETAIL",
1011
]

β€Žfastapi_class/exception/handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
24
from collections.abc import Iterable
35
from typing import Any

β€Žfastapi_class/openapi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
from collections.abc import Callable, Iterable
35

@@ -40,7 +42,8 @@ def _exceptions_to_responses(
4042
exc = exception if isinstance(exception, HTTPException) else exception()
4143
except TypeError:
4244
logger.warning(
43-
"Exception %s was failed to be parsed. Make sure it's either an HTTPException instance or it's a factory function with arguments having default values."
45+
"Exception %s was failed to be parsed. Make sure it's either an HTTPException instance or it's a "
46+
"factory function with arguments having default values."
4447
)
4548
exc = HTTPException(status.HTTP_400_BAD_REQUEST, detail=str(exception))
4649
if exc.status_code not in mapping:

β€Žfastapi_class/routers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from collections.abc import Callable, Iterable
24
from dataclasses import dataclass
35
from enum import Enum
@@ -18,7 +20,7 @@ class Method(str, Enum):
1820

1921
@dataclass(frozen=True, init=True, repr=True)
2022
class Metadata:
21-
methods: Iterable[Method]
23+
methods: Iterable[str | Method]
2224
name: str | None = None
2325
path: str | None = None
2426
status_code: int | None = None
@@ -28,7 +30,7 @@ class Metadata:
2830

2931
def __getattr__(self, __name: str) -> Any | Callable[[Any], Any]:
3032
if __name.endswith(Metadata.__default_method_suffix):
31-
prefix = __name.removesuffix(Metadata.__default_method_suffix)
33+
prefix = __name.replace(Metadata.__default_method_suffix, "")
3234
if hasattr(self, prefix):
3335
return lambda _default: getattr(self, prefix, None) or _default
3436
return getattr(self, prefix)

β€Žfastapi_class/views.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import re
24
from collections.abc import Callable, Iterable
35

@@ -7,12 +9,6 @@
79
from fastapi_class.openapi import _exceptions_to_responses
810
from fastapi_class.routers import Metadata, Method
911

10-
11-
def _view_class_name_default_parser(cls: object, method: str):
12-
class_name = " ".join(re.findall(r"[A-Z][^A-Z]*", cls.__name__.replace("View", "")))
13-
return f"{method.capitalize()} {class_name}"
14-
15-
1612
COMMON_KEYWORD = "common"
1713
RESPONSE_MODEL_ATTRIBUTE_NAME = "RESPONSE_MODEL"
1814
RESPONSE_CLASS_ATTRIBUTE_NAME = "RESPONSE_CLASS"

β€Žpyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66
name = "fastapi_class"
77
description = "Simplifies class-based views for more organized and maintainable code in FastAPI."
88
readme = "README.md"
9-
requires-python = ">=3.10"
9+
requires-python = ">=3.8"
1010
license = "MIT"
1111
authors = [
1212
{ name = "Yasser Tahiri", email = "[email protected]" },
@@ -20,6 +20,8 @@ classifiers = [
2020
"Framework :: Pydantic",
2121
"Framework :: AsyncIO",
2222
"Programming Language :: Python",
23+
"Programming Language :: Python :: 3.8",
24+
"Programming Language :: Python :: 3.9",
2325
"Programming Language :: Python :: 3.10",
2426
"Programming Language :: Python :: 3.11",
2527
"Programming Language :: Python :: 3 :: Only",

β€Žtests/test_exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from unittest.mock import patch
24

35
import pytest

β€Žtests/test_metadata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Any
24

35
import pytest

0 commit comments

Comments
Β (0)