From 021da3837358c416f4fcb96d79772e80d9071729 Mon Sep 17 00:00:00 2001 From: Ryu JuHeon Date: Tue, 13 Jul 2021 16:32:54 +0900 Subject: [PATCH] style(app,blueprints): add some type hints (#2196) * style(app,blueprints): add some type hints * style(app): option is Any * style(blueprints): url prefix default value is ``""`` * style(app): backward compatible * style(app): backward compatible * style(blueprints): defult is None * style(app): apply code style (black) --- sanic/app.py | 13 ++++++++++--- sanic/blueprints.py | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index ec9027b5..07c5a9e8 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -30,6 +30,7 @@ from typing import ( List, Optional, Set, + Tuple, Type, Union, ) @@ -411,7 +412,13 @@ class Sanic(BaseSanic): self.websocket_enabled = enable - def blueprint(self, blueprint, **options): + def blueprint( + self, + blueprint: Union[ + Blueprint, List[Blueprint], Tuple[Blueprint], BlueprintGroup + ], + **options: Any, + ): """Register a blueprint on the application. :param blueprint: Blueprint object or (list, tuple) thereof @@ -869,7 +876,7 @@ class Sanic(BaseSanic): *, debug: bool = False, auto_reload: Optional[bool] = None, - ssl: Union[dict, SSLContext, None] = None, + ssl: Union[Dict[str, str], SSLContext, None] = None, sock: Optional[socket] = None, workers: int = 1, protocol: Optional[Type[Protocol]] = None, @@ -999,7 +1006,7 @@ class Sanic(BaseSanic): port: Optional[int] = None, *, debug: bool = False, - ssl: Union[dict, SSLContext, None] = None, + ssl: Union[Dict[str, str], SSLContext, None] = None, sock: Optional[socket] = None, protocol: Type[Protocol] = None, backlog: int = 100, diff --git a/sanic/blueprints.py b/sanic/blueprints.py index 2431f849..f0d7f431 100644 --- a/sanic/blueprints.py +++ b/sanic/blueprints.py @@ -146,10 +146,10 @@ class Blueprint(BaseSanic): @staticmethod def group( - *blueprints, - url_prefix="", - version=None, - strict_slashes=None, + *blueprints: Union[Blueprint, BlueprintGroup], + url_prefix: Optional[str] = None, + version: Optional[Union[int, str, float]] = None, + strict_slashes: Optional[bool] = None, version_prefix: str = "/v", ): """