strict typing, change colors a bit, architecture depending lock

This commit is contained in:
2021-03-13 16:57:58 +03:00
parent 9410c521a1
commit 4b98b21a70
12 changed files with 45 additions and 25 deletions

View File

@ -17,15 +17,19 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from aiohttp.web import middleware, Request, Response
from aiohttp.web import middleware, Request
from aiohttp.web_exceptions import HTTPClientError
from aiohttp.web_response import StreamResponse
from logging import Logger
from typing import Callable
from typing import Awaitable, Callable
def exception_handler(logger: Logger) -> Callable:
HandlerType = Callable[[Request], Awaitable[StreamResponse]]
def exception_handler(logger: Logger) -> Callable[[Request, HandlerType], Awaitable[StreamResponse]]:
@middleware
async def handle(request: Request, handler: Callable) -> Response:
async def handle(request: Request, handler: HandlerType) -> StreamResponse:
try:
return await handler(request)
except HTTPClientError:

View File

@ -27,4 +27,5 @@ class BaseView(View):
@property
def service(self) -> Watcher:
return self.request.app['watcher']
watcher: Watcher = self.request.app['watcher']
return watcher

View File

@ -17,7 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from aiohttp_jinja2 import template
import aiohttp_jinja2 # type: ignore
from typing import Any, Dict
import ahriman.version as version
@ -27,7 +28,7 @@ from ahriman.web.views.base import BaseView
class IndexView(BaseView):
@template("build-status.jinja2")
@aiohttp_jinja2.template("build-status.jinja2") # type: ignore
async def get(self) -> Dict[str, Any]:
# some magic to make it jinja-friendly
packages = [

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import aiohttp_jinja2
import aiohttp_jinja2 # type: ignore
import jinja2
import logging