Skip to content

Commit

Permalink
type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Jan 7, 2024
1 parent f8e781c commit 3ef90c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
venv
.pytest_cache
test.py
.mypy_cache
13 changes: 9 additions & 4 deletions cbfa/class_based.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from typing import Callable, Type, Optional, Any

from fastapi import FastAPI


class ClassBased:
methods = (
'get',
Expand All @@ -11,11 +16,11 @@ class ClassBased:
'patch',
)

def __init__(self, app):
def __init__(self, app: FastAPI) -> None:
self.app = app

def __call__(self, *args, **kwargs):
def decorator(Class):
def __call__(self, *args: Any, **kwargs: Any) -> Callable[[Type[Any]], Type[Any]]:
def decorator(Class: Type[Any]) -> Type[Any]:
for method_name in self.methods:
if hasattr(Class, method_name):
method = self.get_method(method_name)
Expand All @@ -28,5 +33,5 @@ def decorator(Class):
return Class
return decorator

def get_method(self, method_name):
def get_method(self, method_name: str) -> Optional[Callable[..., Any]]:
return getattr(self.app, method_name, None)

0 comments on commit 3ef90c4

Please sign in to comment.