Skip to content

Commit 46ab186

Browse files
docs(examples): add type hints to things WSGI/ASGI samples (#2698)
* docs(examples): add type hints to things WSGI/ASGI samples Annotate on_get request/response parameters in the tutorial examples as a small first slice of #1820. No runtime behavior change. Signed-off-by: Alex Chen <l46983284@gmail.com> * docs(examples): type ASGI things handlers with falcon.asgi types Use falcon.asgi.Request/Response in the ASGI sample so the annotations match the ASGI app surface, not the WSGI base classes. Signed-off-by: Alex Chen <l46983284@gmail.com> * docs(examples): drop future annotations; sync README snippets Remove unnecessary from __future__ import annotations from the short things samples and mirror the typed responder signatures (plus ASGI Request/Response imports) in the inline README.rst copies. Signed-off-by: Alex Chen <l46983284@gmail.com>
1 parent c1ba507 commit 46ab186

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ WSGI app (the ASGI version is included further down):
344344
# other things) that you think in terms of resources and state
345345
# transitions, which map to HTTP verbs.
346346
class ThingsResource:
347-
def on_get(self, req, resp):
347+
def on_get(self, req: falcon.Request, resp: falcon.Response) -> None:
348348
"""Handles GET requests"""
349349
resp.status = falcon.HTTP_200 # This is the default status
350350
resp.content_type = falcon.MEDIA_TEXT # Default is JSON, so override
@@ -392,13 +392,15 @@ The ASGI version of the example is similar:
392392
393393
import falcon
394394
import falcon.asgi
395+
from falcon.asgi import Request
396+
from falcon.asgi import Response
395397
396398
397399
# Falcon follows the REST architectural style, meaning (among
398400
# other things) that you think in terms of resources and state
399401
# transitions, which map to HTTP verbs.
400402
class ThingsResource:
401-
async def on_get(self, req, resp):
403+
async def on_get(self, req: Request, resp: Response) -> None:
402404
"""Handles GET requests"""
403405
resp.status = falcon.HTTP_200 # This is the default status
404406
resp.content_type = falcon.MEDIA_TEXT # Default is JSON, so override

examples/things.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# other things) that you think in terms of resources and state
1111
# transitions, which map to HTTP verbs.
1212
class ThingsResource:
13-
def on_get(self, req, resp):
13+
def on_get(self, req: falcon.Request, resp: falcon.Response) -> None:
1414
"""Handles GET requests"""
1515
resp.status = falcon.HTTP_200 # This is the default status
1616
resp.content_type = falcon.MEDIA_TEXT # Default is JSON, so override

examples/things_asgi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import falcon
44
import falcon.asgi
5+
from falcon.asgi import Request
6+
from falcon.asgi import Response
57

68

79
# Falcon follows the REST architectural style, meaning (among
810
# other things) that you think in terms of resources and state
911
# transitions, which map to HTTP verbs.
1012
class ThingsResource:
11-
async def on_get(self, req, resp):
13+
async def on_get(self, req: Request, resp: Response) -> None:
1214
"""Handles GET requests"""
1315
resp.status = falcon.HTTP_200 # This is the default status
1416
resp.content_type = falcon.MEDIA_TEXT # Default is JSON, so override

0 commit comments

Comments
 (0)