From de157ad3dff76a23d1133f81de22bc727a34afe6 Mon Sep 17 00:00:00 2001 From: Vytautas Liuolia Date: Fri, 4 Oct 2024 22:38:17 +0200 Subject: [PATCH 1/6] docs: move frontpage quote example to a separate file --- docs/index.rst | 22 ++-------------------- tests/test_examples.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 359062b5f..329659791 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,26 +16,8 @@ We like to think of Falcon as the *Dieter Rams* of web frameworks. Falcon encourages the REST architectural style, and tries to do as little as possible while remaining highly effective. -.. code:: python - - import falcon - - class QuoteResource: - def on_get(self, req, resp): - """Handles GET requests""" - quote = { - 'quote': ( - "I've always been more interested in " - "the future than in the past." - ), - 'author': 'Grace Hopper' - } - - resp.media = quote - - - app = falcon.App() - app.add_route('/quote', QuoteResource()) +.. literalinclude:: ../examples/quote.py + :language: python For a fully working example, check out the :ref:`quickstart`. diff --git a/tests/test_examples.py b/tests/test_examples.py index 5fd5b1db7..e203b8233 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -13,6 +13,18 @@ import falcon.testing as testing +def test_quote(util): + quote = util.load_module('examples/quote.py') + + resp = testing.simulate_get(quote.app, '/quote') + + assert resp.status_code == 200 + assert resp.json == { + 'author': 'Grace Hopper', + 'quote': "I've always been more interested in the future than in the past.", + } + + def test_things(asgi, util): suffix = '_asgi' if asgi else '' things = util.load_module(f'examples/things{suffix}.py') From bec94a5f031ed4681145c90c9e00f3c5cf4edaeb Mon Sep 17 00:00:00 2001 From: Vytautas Liuolia Date: Fri, 4 Oct 2024 22:38:41 +0200 Subject: [PATCH 2/6] chore: actually add the new file --- examples/quote.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 examples/quote.py diff --git a/examples/quote.py b/examples/quote.py new file mode 100644 index 000000000..71779fed5 --- /dev/null +++ b/examples/quote.py @@ -0,0 +1,15 @@ +import falcon + + +class QuoteResource: + def on_get(self, req: falcon.Request, resp: falcon.Response) -> None: + """Handle GET requests.""" + + resp.media = { + 'quote': "I've always been more interested in the future than in the past.", + 'author': 'Grace Hopper', + } + + +app = falcon.App() +app.add_route('/quote', QuoteResource()) From e927592c743d5561de9fcf64e8f94c89b73c9ab8 Mon Sep 17 00:00:00 2001 From: Vytautas Liuolia Date: Fri, 4 Oct 2024 22:48:20 +0200 Subject: [PATCH 3/6] docs(REAME): disable cythonization of editable installs --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index dfa18e0c6..2e5d1b3fc 100644 --- a/README.rst +++ b/README.rst @@ -278,7 +278,7 @@ available to your app without having to reinstall the package: .. code:: bash $ cd falcon - $ pip install -e . + $ FALCON_DISABLE_CYTHON=Y pip install -e . You can manually test changes to the Falcon framework by switching to the directory of the cloned repo and then running pytest: From b08314d9aceec75b4e4fa3bfef6b2c50c2723757 Mon Sep 17 00:00:00 2001 From: Vytautas Liuolia Date: Fri, 4 Oct 2024 23:45:43 +0200 Subject: [PATCH 4/6] docs: remove an empty line from quote.py --- examples/quote.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/quote.py b/examples/quote.py index 71779fed5..eb6a62469 100644 --- a/examples/quote.py +++ b/examples/quote.py @@ -4,7 +4,6 @@ class QuoteResource: def on_get(self, req: falcon.Request, resp: falcon.Response) -> None: """Handle GET requests.""" - resp.media = { 'quote': "I've always been more interested in the future than in the past.", 'author': 'Grace Hopper', From 6f68c50e9df9d776a5caeb0187a136bd61c6747e Mon Sep 17 00:00:00 2001 From: Vytautas Liuolia Date: Sat, 5 Oct 2024 15:49:23 +0200 Subject: [PATCH 5/6] docs: fix a comment and add a note --- CONTRIBUTING.md | 8 ++++++++ falcon/util/mediatypes.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5422355cc..0307fb191 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,14 @@ $ pip install -U ruff $ ruff format ``` +You can also reformat your code, and apply safe ``ruff`` fixes, via the +``reformat`` ``tox`` environment: + +```bash +$ pip install -U tox +$ tox -e reformat +``` + You can check all this by running ``tox`` from within the Falcon project directory. Your environment must be based on CPython 3.10, 3.11, 3.12 or 3.13: diff --git a/falcon/util/mediatypes.py b/falcon/util/mediatypes.py index 9aba2e38c..1d5218d5c 100644 --- a/falcon/util/mediatypes.py +++ b/falcon/util/mediatypes.py @@ -216,8 +216,8 @@ def match_score(self, media_type: _MediaType) -> Tuple[int, int, int, int, float # PERF(vytas): It is possible to cache a classmethod too, but the invocation is # less efficient, especially in the case of a cache hit. -# NOTE(vytas): Also, if we decide to make these classes public, we either need -# to keep these cached parsers private, or to make sure we use frozen classes. +# NOTE(vytas): Also, if we decide to make these classes public, we need to keep +# these cached parsers private. _parse_media_type = functools.lru_cache(_MediaType.parse) _parse_media_range = functools.lru_cache(_MediaRange.parse) From cc00c506b99a7867405b86644ed2ee94ad6f5329 Mon Sep 17 00:00:00 2001 From: Vytautas Liuolia Date: Sat, 5 Oct 2024 15:54:00 +0200 Subject: [PATCH 6/6] chore(changes): aggregate 4.0 contributors so far --- AUTHORS | 1 + docs/changes/4.0.0.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 6f4f2451e..95b44b1fd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -198,6 +198,7 @@ listed below by date of first contribution: * Dave Tapley (davetapley) * Agustin Arce (aarcex3) * Christian Grossmüller (chgad) +* Sai Prathik R (prathik2401) (et al.) diff --git a/docs/changes/4.0.0.rst b/docs/changes/4.0.0.rst index f04f2c063..dea98a584 100644 --- a/docs/changes/4.0.0.rst +++ b/docs/changes/4.0.0.rst @@ -101,7 +101,9 @@ Many thanks to all of our talented and stylish contributors for this release! - `mgorny `__ - `mihaitodor `__ - `MRLab12 `__ +- `myusko `__ - `nfsec `__ +- `prathik2401 `__ - `RioAtHome `__ - `TigreModerata `__ - `vgerak `__