chore(util): preserve LRU cache decorator types#2643
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2643 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 7985 7990 +5
Branches 1103 1103
=========================================
+ Hits 7985 7990 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
I don't think we need newsfragments for internal improvements that are not surface to the framework's user. I'll unlink this file unless you vehemently object.
vytas7
left a comment
There was a problem hiding this comment.
Thanks, this looks good on the whole, however I'd like to make a couple of changes before merging this (commented inline).
| while not resp_event_collector.status: | ||
| await asyncio.sleep(0) | ||
|
|
||
| status = resp_event_collector.status |
There was a problem hiding this comment.
Can you please undo these unrelated changes?
Or does going via a variable somehow help with typing?
Since this is the testing client's code, we are not that concerned about performance, but it would still be good to understand why exactly we need this pattern.
| # public Falcon interface. | ||
| from .deprecation import deprecated | ||
|
|
||
| if TYPE_CHECKING: |
There was a problem hiding this comment.
These protocols look good at first glance. 👍
But could you please move them to falcon/_typing.py? We are trying to colocate such definitions in that module.
Summary of Changes
Use
ParamSpecto type Falcon's internal LRU cache decorator factory so wrapped callables keep their original signatures and exposecache_clear()to static type checkers.This removes the now-unnecessary
type: ignorecomments 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
tox.docs/.docs/.versionadded,versionchanged, ordeprecateddirectives.docs/_newsfragments/, with the file name format{issue_number}.{fragment_type}.rst. (Runtox -e towncrier, and inspectdocs/_build/html/changes/in the browser to ensure it renders correctly.)Validation performed:
python -m mypy --strict falconpython -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.pypython -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.pypython -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 -qpython tools/towncrier_draft.py --dry-rungit diff --check