From fd221e0251ba7c79dcad0d692a7ab954910b3d81 Mon Sep 17 00:00:00 2001 From: Harsha Narayana Date: Sun, 7 Mar 2021 18:00:35 +0530 Subject: [PATCH] GIT-2045: use Optional instead of Union for Typing --- sanic/blueprint_group.py | 10 +++------- sanic/models/futures.py | 14 +++++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sanic/blueprint_group.py b/sanic/blueprint_group.py index ce7513fc5b..b79e7fea61 100644 --- a/sanic/blueprint_group.py +++ b/sanic/blueprint_group.py @@ -1,5 +1,5 @@ from collections.abc import MutableSequence -from typing import List, Union +from typing import List, Optional, Union import sanic @@ -98,7 +98,7 @@ def version(self) -> Union[None, str, int, float]: return self._version @property - def strict_slashes(self) -> Union[None, bool]: + def strict_slashes(self) -> Optional[bool]: """ URL Slash termination behavior configuration @@ -171,11 +171,7 @@ def _sanitize_blueprint(self, bp: "sanic.Blueprint") -> "sanic.Blueprint": merged_prefix = "/".join( u.strip("/") for u in [self._url_prefix, bp.url_prefix or ""] ).rstrip("/") - bp.url_prefix = ( - f"/{merged_prefix}" - if not merged_prefix.startswith("/") - else merged_prefix - ) + bp.url_prefix = f"/{merged_prefix}" for _attr in ["version", "strict_slashes"]: if getattr(bp, _attr) is None: setattr(bp, _attr, getattr(self, _attr)) diff --git a/sanic/models/futures.py b/sanic/models/futures.py index b7cbf7caa7..083b98157c 100644 --- a/sanic/models/futures.py +++ b/sanic/models/futures.py @@ -1,5 +1,5 @@ from pathlib import PurePath -from typing import NamedTuple, List, Union, Iterable +from typing import NamedTuple, List, Union, Iterable, Optional from sanic.models.handler_types import ( ListenerType, @@ -11,15 +11,15 @@ class FutureRoute(NamedTuple): handler: str uri: str - methods: Union[None, Iterable[str]] + methods: Optional[Iterable[str]] host: str strict_slashes: bool stream: bool - version: Union[None, int] + version: Optional[int] name: str ignore_body: bool websocket: bool - subprotocols: Union[None, List[str]] + subprotocols: Optional[List[str]] unquote: bool static: bool @@ -47,6 +47,6 @@ class FutureStatic(NamedTuple): use_content_range: bool stream_large_files: bool name: str - host: Union[None, str] - strict_slashes: Union[None, bool] - content_type: Union[None, bool] + host: Optional[str] + strict_slashes: Optional[bool] + content_type: Optional[bool]