Skip to content

Commit

Permalink
typing: type response
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Aug 27, 2024
1 parent 4da1953 commit 9a4734a
Show file tree
Hide file tree
Showing 15 changed files with 563 additions and 394 deletions.
14 changes: 9 additions & 5 deletions falcon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
ClassVar,
Dict,
FrozenSet,
IO,
Iterable,
List,
Literal,
Expand Down Expand Up @@ -62,6 +61,7 @@
from falcon.typing import ErrorSerializer
from falcon.typing import FindMethod
from falcon.typing import ProcessResponseMethod
from falcon.typing import ReadableIO
from falcon.typing import ResponderCallable
from falcon.typing import SinkCallable
from falcon.typing import SinkPrefix
Expand Down Expand Up @@ -1191,7 +1191,9 @@ def _handle_exception(
def _get_body(
self,
resp: Response,
wsgi_file_wrapper: Optional[Callable[[IO[bytes], int], Iterable[bytes]]] = None,
wsgi_file_wrapper: Optional[
Callable[[ReadableIO, int], Iterable[bytes]]
] = None,
) -> Tuple[Iterable[bytes], Optional[int]]:
"""Convert resp content into an iterable as required by PEP 333.
Expand Down Expand Up @@ -1229,11 +1231,13 @@ def _get_body(
# TODO(kgriffs): Make block size configurable at the
# global level, pending experimentation to see how
# useful that would be. See also the discussion on
# this GitHub PR: http://goo.gl/XGrtDz
iterable = wsgi_file_wrapper(stream, self._STREAM_BLOCK_SIZE)
# this GitHub PR:
# https://github.com/falconry/falcon/pull/249#discussion_r11269730
iterable = wsgi_file_wrapper(stream, self._STREAM_BLOCK_SIZE) # type: ignore[arg-type]

Check warning on line 1236 in falcon/app.py

View check run for this annotation

Codecov / codecov/patch

falcon/app.py#L1236

Added line #L1236 was not covered by tests
else:
iterable = helpers.CloseableStreamIterator(
stream, self._STREAM_BLOCK_SIZE
stream, # type: ignore[arg-type]
self._STREAM_BLOCK_SIZE,
)
else:
iterable = stream
Expand Down
12 changes: 6 additions & 6 deletions falcon/asgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from falcon.asgi_spec import AsgiSendMsg
from falcon.asgi_spec import EventType
from falcon.asgi_spec import WSCloseCode
from falcon.constants import _UNSET
from falcon.constants import MEDIA_JSON
from falcon.errors import CompatibilityError
from falcon.errors import HTTPBadRequest
Expand All @@ -60,6 +59,7 @@
from falcon.typing import AsgiResponderWsCallable
from falcon.typing import AsgiSend
from falcon.typing import AsgiSinkCallable
from falcon.typing import MISSING
from falcon.typing import SinkPrefix
from falcon.util import get_argnames
from falcon.util.misc import is_python_func
Expand Down Expand Up @@ -552,9 +552,9 @@ async def __call__( # type: ignore[override] # noqa: C901
data = resp._data

if data is None and resp._media is not None:
# NOTE(kgriffs): We use a special _UNSET singleton since
# NOTE(kgriffs): We use a special MISSING singleton since
# None is ambiguous (the media handler might return None).
if resp._media_rendered is _UNSET:
if resp._media_rendered is MISSING:
opt = resp.options
if not resp.content_type:
resp.content_type = opt.default_media_type
Expand All @@ -577,7 +577,7 @@ async def __call__( # type: ignore[override] # noqa: C901
data = text.encode()
except AttributeError:
# NOTE(kgriffs): Assume it was a bytes object already
data = text
data = text # type: ignore[assignment]

Check warning on line 580 in falcon/asgi/app.py

View check run for this annotation

Codecov / codecov/patch

falcon/asgi/app.py#L580

Added line #L580 was not covered by tests

else:
# NOTE(vytas): Custom response type.
Expand Down Expand Up @@ -1028,9 +1028,9 @@ def _schedule_callbacks(self, resp: Response) -> None:

loop = asyncio.get_running_loop()

for cb, is_async in callbacks: # type: ignore[attr-defined]
for cb, is_async in callbacks or ():
if is_async:
loop.create_task(cb())
loop.create_task(cb()) # type: ignore[arg-type]

Check warning on line 1033 in falcon/asgi/app.py

View check run for this annotation

Codecov / codecov/patch

falcon/asgi/app.py#L1033

Added line #L1033 was not covered by tests
else:
loop.run_in_executor(None, cb)

Expand Down
Loading

0 comments on commit 9a4734a

Please sign in to comment.