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: add more type hints #2183

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
96ecda4
feat: Type app helpers module
copalco Aug 16, 2023
00739d1
feat: Add typing to errors module
copalco Aug 16, 2023
b550754
feat: Add typings to forwarded module
copalco Aug 16, 2023
ccc5c7c
feat: Add typing to hooks
copalco Aug 18, 2023
0fd6d7a
feat: Add typing to falcon hooks
copalco Aug 18, 2023
4a7daf0
feat: Add typing to http_error module
copalco Aug 18, 2023
31e4e0d
feat: Extract RawHeaders and NormalizedHeaders to typing module
copalco Aug 18, 2023
763fc7a
feat: Extract status to typing module
copalco Aug 18, 2023
1d13cd0
feat: Add typing to http_status module
copalco Aug 18, 2023
32fbd7d
feat: Add typing to inspect module
copalco Aug 18, 2023
42abb3a
feat: Add typing to middleware module
copalco Aug 18, 2023
2e05a28
feat: Replace protocol with interface
copalco Aug 19, 2023
967d3e8
feat: Add typing to redirects
copalco Aug 19, 2023
0d1aa47
feat: Type vendor mimeparse
copalco Aug 20, 2023
3214966
Changed RawHeaders to not include None
copalco Aug 24, 2023
2c48bc6
Reformated imports
copalco Aug 24, 2023
0368deb
Test that interface raises not implemented
copalco Aug 24, 2023
4e1d1c5
Type algorithm int values as float
copalco Aug 24, 2023
3282355
Changed allowed methods to Iterable
copalco Aug 24, 2023
9855a97
Imported annotations in hooks
copalco Aug 24, 2023
8709da4
Change argnames type to list of strings
copalco Aug 24, 2023
0e680bd
Changed Dict to mutable mapping
copalco Aug 24, 2023
1ec1629
Fixed formatting
copalco Aug 24, 2023
a1c8a91
Remove unused imports
copalco Aug 24, 2023
917db59
Fix typing
copalco Aug 24, 2023
5f9984f
Replaced assert with cast
copalco Aug 24, 2023
edc739c
Fix blue
copalco Aug 24, 2023
ae03c3e
Type resource as object
copalco Aug 24, 2023
a66ab36
Fix style
copalco Aug 24, 2023
14e9d30
Revert "Type algorithm int values as float"
copalco Aug 29, 2023
51d0b43
Revert "feat: Type vendor mimeparse"
copalco Aug 29, 2023
73c42b9
Ignore vendore package
copalco Aug 30, 2023
4a5b2c5
Use async package instead of importing AsyncRequest and AsyncResponse…
copalco Aug 30, 2023
99f8bb2
Solve circular imports while typing
copalco Aug 30, 2023
ee2ff5e
Fix style
copalco Aug 30, 2023
6e02f9a
Changed inspect obj type to Any
copalco Aug 31, 2023
f7bd33c
Import annotations where missing
copalco Sep 4, 2023
7470dae
Replace Union with | where future annotations imported
copalco Sep 6, 2023
e44512e
Revert "Replace Union with | where future annotations imported"
copalco Sep 6, 2023
d5a87c5
Improve imports to avoid them inside functions
CaselIT Sep 9, 2023
0f9a0c3
Fix typo
copalco Oct 16, 2023
1d793d4
Rename Kwargs to HTTPErrorKeywordArgs
copalco Oct 16, 2023
a3b6aec
Import whole package insted of specific types
copalco Oct 16, 2023
ba4e748
Fix style
copalco Oct 17, 2023
077ed14
Replace Serializer and MediaHandler with protocol
copalco Oct 17, 2023
fbfc4b4
Add assertion reason message
copalco Oct 27, 2023
b5e704f
Fix import issue
copalco Oct 29, 2023
95ede1b
Fix import order
copalco Oct 30, 2023
a0a481c
Fix coverage issues
copalco Nov 5, 2023
b2b94d8
Add ResponderOrResource and Action types
copalco Nov 5, 2023
53df7c0
Improve responders typing
copalco Oct 30, 2023
db12db8
Merge branch 'master' into add_type_hints
vytas7 Apr 14, 2024
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 @@ -42,7 +41,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 @@ -673,7 +671,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:
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


class EventType:
Expand Down