Skip to content

fix(util): preserve LRU cache decorator types#2643

Open
paulkagiri wants to merge 1 commit into
falconry:masterfrom
paulkagiri:type-lru-cache-decorators
Open

fix(util): preserve LRU cache decorator types#2643
paulkagiri wants to merge 1 commit into
falconry:masterfrom
paulkagiri:type-lru-cache-decorators

Conversation

@paulkagiri
Copy link
Copy Markdown

Summary of Changes

Use ParamSpec to type Falcon's internal LRU cache decorator factory so wrapped callables keep their original signatures and expose cache_clear() to static type checkers.

This removes the now-unnecessary type: ignore comments around cached resolver/status helpers and adds the narrow assertions needed where the ASGI testing client converts a collected response status after the app has responded.

Related Issues

Closes #2629

Pull Request Checklist

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
  • Performed automated tests and code quality checks by running tox.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run tox -e towncrier, and inspect docs/_build/html/changes/ in the browser to ensure it renders correctly.)
  • LLM output, if any, has been carefully reviewed and tested by a human developer. (See also: Use of LLMs ("AI").)

Validation performed:

  • python -m mypy --strict falcon
  • python -m ruff format --check falcon/util/misc.py falcon/media/handlers.py falcon/http_error.py falcon/http_status.py falcon/response.py falcon/testing/client.py
  • python -m ruff check falcon/util/misc.py falcon/media/handlers.py falcon/http_error.py falcon/http_status.py falcon/response.py falcon/testing/client.py
  • python -m pytest tests/test_media_handlers.py tests/test_httpstatus.py tests/test_utils.py::TestFalconUtils::test_code_to_http_status tests/test_utils.py::TestFalconUtils::test_http_status_to_code tests/asgi/test_hello_asgi.py -q
  • python tools/towncrier_draft.py --dry-run
  • git diff --check

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b1b683a) to head (710250d).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2643   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         7976      7981    +5     
  Branches      1102      1102           
=========================================
+ Hits          7976      7981    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use ParamSpec to type LRU cache decorators

1 participant