Skip to content

Commit

Permalink
GIT-2045: use Optional instead of Union for Typing
Browse files Browse the repository at this point in the history
  • Loading branch information
harshanarayana committed Mar 7, 2021
1 parent 188653f commit fd221e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 3 additions & 7 deletions sanic/blueprint_group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import MutableSequence
from typing import List, Union
from typing import List, Optional, Union

import sanic

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions sanic/models/futures.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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]

0 comments on commit fd221e0

Please sign in to comment.