Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: type more falcon modules #2171

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a4093e4
feat: Type app helpers module
copalco Aug 16, 2023
9752b23
feat: Add typing to errors module
copalco Aug 16, 2023
8843cb5
feat: Add typings to forwarded module
copalco Aug 16, 2023
5f80341
feat: Add typing to hooks
copalco Aug 18, 2023
1f52765
feat: Add typing to falcon hooks
copalco Aug 18, 2023
084c327
feat: Add typing to http_error module
copalco Aug 18, 2023
0797b3d
feat: Extract RawHeaders and NormalizedHeaders to typing module
copalco Aug 18, 2023
af73715
feat: Extract status to typing module
copalco Aug 18, 2023
23d03df
feat: Add typing to http_status module
copalco Aug 18, 2023
c0aaf47
feat: Add typing to inspect module
copalco Aug 18, 2023
1697003
feat: Add typing to middleware module
copalco Aug 18, 2023
0bf142e
feat: Replace protocol with interface
copalco Aug 19, 2023
7a07eaa
feat: Add typing to redirects
copalco Aug 19, 2023
01338e3
feat: Type vendor mimeparse
copalco Aug 20, 2023
5abe369
Changed RawHeaders to not include None
copalco Aug 24, 2023
7e30e48
Reformated imports
copalco Aug 24, 2023
ec48fb5
Test that interface raises not implemented
copalco Aug 24, 2023
44f4487
Type algorithm int values as float
copalco Aug 24, 2023
9822048
Changed allowed methods to Iterable
copalco Aug 24, 2023
2630826
Imported annotations in hooks
copalco Aug 24, 2023
9046af3
Change argnames type to list of strings
copalco Aug 24, 2023
729d3d1
Changed Dict to mutable mapping
copalco Aug 24, 2023
75baaf5
Fixed formatting
copalco Aug 24, 2023
1a1a115
Remove unused imports
copalco Aug 24, 2023
6703a2e
Fix typing
copalco Aug 24, 2023
37b821f
Replaced assert with cast
copalco Aug 24, 2023
491fc90
Fix blue
copalco Aug 24, 2023
d277180
Type resource as object
copalco Aug 24, 2023
a0a4110
Fix style
copalco Aug 24, 2023
aed01aa
Revert "Type algorithm int values as float"
copalco Aug 29, 2023
42236b6
Revert "feat: Type vendor mimeparse"
copalco Aug 29, 2023
659b863
Ignore vendore package
copalco Aug 30, 2023
c074212
Use async package instead of importing AsyncRequest and AsyncResponse…
copalco Aug 30, 2023
aa5321a
Solve circular imports while typing
copalco Aug 30, 2023
ff1d995
Fix style
copalco Aug 30, 2023
a50fd3e
Changed inspect obj type to Any
copalco Aug 31, 2023
79d7093
Import annotations where missing
copalco Sep 4, 2023
f844071
Replace Union with | where future annotations imported
copalco Sep 6, 2023
8b06f45
Revert "Replace Union with | where future annotations imported"
copalco Sep 6, 2023
08f78e9
Improve imports to avoid them inside functions
CaselIT Sep 9, 2023
1317945
Fix typo
copalco Oct 16, 2023
5de1831
Rename Kwargs to HTTPErrorKeywordArgs
copalco Oct 16, 2023
d78d57b
Import whole package insted of specific types
copalco Oct 16, 2023
6d4882d
Fix style
copalco Oct 17, 2023
6ad28c4
Replace Serializer and MediaHandler with protocol
copalco Oct 17, 2023
cd35341
Add assertion reason message
copalco Oct 27, 2023
14909a7
Fix import issue
copalco Oct 29, 2023
208c809
Fix import order
copalco Oct 30, 2023
f06d56b
Fix coverage issues
copalco Nov 5, 2023
cf3fce0
Add ResponderOrResource and Action types
copalco Nov 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions falcon/app.py
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

"""Falcon App class."""

from functools import wraps
from inspect import iscoroutinefunction
import pathlib
Expand Down Expand Up @@ -41,7 +40,6 @@
from falcon.util import misc
from falcon.util.misc import code_to_http_status


# PERF(vytas): On Python 3.5+ (including cythonized modules),
# reference via module global is faster than going via self
_BODILESS_STATUS_CODES = frozenset(
Expand Down Expand Up @@ -653,7 +651,7 @@ def add_static_route(
self._static_routes.insert(0, (sr, sr, False))
self._update_sink_and_static_routes()

def add_sink(self, sink: Callable, prefix: SinkPrefix = r'/'):
def add_sink(self, sink: Callable, prefix: SinkPrefix = r'/') -> None:
"""Register a sink method for the App.

If no route matches a request, but the path in the requested URI
Expand Down
11 changes: 6 additions & 5 deletions falcon/app_helpers.py
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Utilities for the App class."""
from __future__ import annotations

from inspect import iscoroutinefunction
from typing import IO, Iterable, List, Tuple
Expand Down Expand Up @@ -201,7 +202,7 @@ def prepare_middleware_ws(middleware: Iterable) -> Tuple[list, list]:
return request_mw, resource_mw


def default_serialize_error(req: Request, resp: Response, exception: HTTPError):
def default_serialize_error(req: Request, resp: Response, exception: HTTPError) -> None:
"""Serialize the given instance of HTTPError.

This function determines which of the supported media types, if
Expand Down Expand Up @@ -280,22 +281,22 @@ class CloseableStreamIterator:
block_size (int): Number of bytes to read per iteration.
"""

def __init__(self, stream: IO, block_size: int):
def __init__(self, stream: IO, block_size: int) -> None:
CaselIT marked this conversation as resolved.
Show resolved Hide resolved
self._stream = stream
self._block_size = block_size

def __iter__(self):
def __iter__(self) -> CloseableStreamIterator:
return self

def __next__(self):
def __next__(self) -> bytes:
data = self._stream.read(self._block_size)

if data == b'':
raise StopIteration
else:
return data

def close(self):
def close(self) -> None:
try:
self._stream.close()
except (AttributeError, TypeError):
Expand Down
1 change: 1 addition & 0 deletions falcon/asgi_spec.py
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Constants, etc. defined by the ASGI specification."""
from __future__ import annotations
CaselIT marked this conversation as resolved.
Show resolved Hide resolved


class EventType:
Expand Down