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(media): add an example for using a custom JSON encoder #2035
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2035 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 63 63
Lines 6707 6707
Branches 1238 1238
=========================================
Hits 6707 6707
Continue to review full report at Codecov.
|
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.
Thanks for this improvement to our docs @maxking!
This is not critical to pass review, but while at it, could you also link to the new paragraph from this FAQ answer: How can I use resp.media with types like datetime?
Working on adding a reference back from FAQ, Sphinx doesn't seem to like sections inside the docstrings and I am trying to see how to create a reference without a section in a paragraph. Will update the PR as soon as I can figure that out. :D |
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.
This LGTM bar one typo.
And wrt linking to a target inside a docstring, it is apparently possible using some kind of marker that isn't a section (as sections are disallowed inside docstring), for instance, a rubric
.
The following seems to work, but it adds visible rubrics that we don't use much elsewhere, so probably not worth the effort:
diff --git a/docs/user/faq.rst b/docs/user/faq.rst
index 9d3f09d..60c104f 100644
--- a/docs/user/faq.rst
+++ b/docs/user/faq.rst
@@ -1239,3 +1239,8 @@ Alternatively, you can set the Cookie header directly as demonstrated in this ve
To include multiple values, simply use ``"; "`` to separate each name-value
pair. For example, if you were to pass ``{'Cookie': 'xxx=yyy; hello=world'}``,
you would get ``{'cookies': {'xxx': 'yyy', 'hello': 'world'}}``.
+
+How do I link to a rubric inside a docstring
+--------------------------------------------
+
+Trying... :ref:`target_to_paragraph`
diff --git a/falcon/media/json.py b/falcon/media/json.py
index e6cb0cf..a0359ae 100644
--- a/falcon/media/json.py
+++ b/falcon/media/json.py
@@ -179,6 +179,10 @@ class JSONHandlerWS(TextBaseHandlerWS):
app = falcon.asgi.App()
app.ws_options.media_handlers[falcon.WebSocketPayloadType.TEXT] = json_handler
+ .. _target_to_paragraph:
+
+ .. rubric:: About ensure_ascii
+
By default, ``ensure_ascii`` is passed to the ``json.dumps`` function.
If you override the ``dumps`` function, you will need to explicitly set
``ensure_ascii`` to ``False`` in order to enable the serialization of
Thanks @vytas7, updated the PR. |
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.
LGTM 👍
(I've taken the liberty of tweaking those rubrics a bit to my liking.)
Thanks for this improvement to our docs, @maxking!
Summary of Changes
Adds an example on how to override the default json encoder used by Falcon.
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
docs/
.docs/
.versionadded
,versionchanged
, ordeprecated
directives.docs/_newsfragments/
, with the file name format{issue_number}.{fragment_type}.rst
. (Runtowncrier --draft
to ensure it renders correctly.)