Skip to content

Commit

Permalink
feat: Add typing to redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
copalco committed Aug 22, 2023
1 parent ba181fd commit 30ad9f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
22 changes: 17 additions & 5 deletions falcon/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# limitations under the License.

"""HTTPStatus specializations for 3xx redirects."""
from typing import Optional

import falcon
from falcon.http_status import HTTPStatus
from falcon.typing_http_data import NormalizedHeaders


class HTTPMovedPermanently(HTTPStatus):
Expand All @@ -37,7 +39,9 @@ class HTTPMovedPermanently(HTTPStatus):
response.
"""

def __init__(self, location, headers=None):
def __init__(
self, location: str, headers: Optional[NormalizedHeaders] = None
) -> None:
if headers is None:
headers = {}
headers.setdefault('location', location)
Expand Down Expand Up @@ -66,7 +70,9 @@ class HTTPFound(HTTPStatus):
response.
"""

def __init__(self, location, headers=None):
def __init__(
self, location: str, headers: Optional[NormalizedHeaders] = None
) -> None:
if headers is None:
headers = {}
headers.setdefault('location', location)
Expand Down Expand Up @@ -100,7 +106,9 @@ class HTTPSeeOther(HTTPStatus):
response.
"""

def __init__(self, location, headers=None):
def __init__(
self, location: str, headers: Optional[NormalizedHeaders] = None
) -> None:
if headers is None:
headers = {}
headers.setdefault('location', location)
Expand Down Expand Up @@ -129,7 +137,9 @@ class HTTPTemporaryRedirect(HTTPStatus):
response.
"""

def __init__(self, location, headers=None):
def __init__(
self, location: str, headers: Optional[NormalizedHeaders] = None
) -> None:
if headers is None:
headers = {}
headers.setdefault('location', location)
Expand All @@ -155,7 +165,9 @@ class HTTPPermanentRedirect(HTTPStatus):
response.
"""

def __init__(self, location, headers=None):
def __init__(
self, location: str, headers: Optional[NormalizedHeaders] = None
) -> None:
if headers is None:
headers = {}
headers.setdefault('location', location)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"falcon.http_status",
"falcon.inspect",
"falcon.middleware",
"falcon.redirects",
"falcon.stream",
]
disallow_untyped_defs = true
Expand Down

0 comments on commit 30ad9f5

Please sign in to comment.