-
-
Notifications
You must be signed in to change notification settings - Fork 944
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
docs(typing): restructure typing docs into a separate chapter #2401
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6fbf085
docs(typing): restructure typing docs into a separate chapter
vytas7 5672979
docs(typing): tweak misc stuff for consistency
vytas7 b42fa00
Merge branch 'master' into breakout-typing-docs
vytas7 fc19e61
Merge branch 'master' into breakout-typing-docs
CaselIT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ Framework Reference | |
inspect | ||
util | ||
testing | ||
typing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
Typing | ||
====== | ||
|
||
Type checking support was introduced in version 4.0. While most of the library is | ||
now typed, further type annotations may be added throughout the 4.x release cycle. | ||
To improve them, we may introduce changes to the typing that do not affect | ||
runtime behavior, but may surface new or different errors with type checkers. | ||
|
||
.. role:: python(code) | ||
:language: python | ||
|
||
.. note:: | ||
All undocumented type aliases coming from ``falcon._typing`` are considered | ||
private to the framework itself, and not meant for annotating applications | ||
using Falcon. To that end, it is advisable to only use classes from the | ||
public interface, and public aliases from :mod:`falcon.typing`, e.g.: | ||
|
||
.. code-block:: python | ||
class MyResource: | ||
def on_get(self, req: falcon.Request, resp: falcon.Response) -> None: | ||
resp.media = {'message': 'Hello, World!'} | ||
If you still decide to reuse the private aliases anyway, they should | ||
preferably be imported inside :python:`if TYPE_CHECKING:` blocks in order | ||
to avoid possible runtime errors after an update. | ||
Also, make sure to :ref:`let us know <chat>` which essential aliases are | ||
missing from the public interface! | ||
|
||
|
||
Known Limitations | ||
----------------- | ||
|
||
Falcon's emphasis on flexibility and performance presents certain | ||
challenges when it comes to adding type annotations to the existing code base. | ||
One notable limitation involves using custom :class:`~falcon.Request` and/or | ||
:class:`~falcon.Response` types in callbacks that are passed back | ||
to the framework, such as when adding an | ||
:meth:`error handler <falcon.App.add_error_handler>`. | ||
|
||
For instance, the following application might unexpectedly not pass type | ||
checking: | ||
|
||
.. code-block:: python | ||
from typing import Any | ||
from falcon import App, HTTPInternalServerError, Request, Response | ||
class MyRequest(Request): | ||
... | ||
def handle_os_error(req: MyRequest, resp: Response, ex: Exception, | ||
params: dict[str, Any]) -> None: | ||
raise HTTPInternalServerError(title='OS error!') from ex | ||
app = App(request_type=MyRequest) | ||
app.add_error_handler(OSError, handle_os_error) | ||
(Please also see the following GitHub issue: | ||
`#2372 <https://github.com/falconry/falcon/issues/2372>`__.) | ||
|
||
.. important:: | ||
This is only a typing limitation that has no effect outside of type | ||
checking -- the above ``app`` will run just fine! | ||
|
||
|
||
Public Type Aliases | ||
------------------- | ||
|
||
.. automodule:: falcon.typing | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,9 +89,3 @@ Other | |
|
||
.. autoclass:: falcon.ETag | ||
:members: | ||
|
||
Type Aliases | ||
------------ | ||
|
||
.. automodule:: falcon.typing | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add somewhere in this section that we are working to remove these limitations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll address this in the 4.0.2 microrelease PR then. That's a good suggestion, but I think it would best fit into the sentence just above this note, where we link to the GitHub issue.