-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
♻️ Clean up legacy code and optimize OpenAPI performance #13874
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
base: master
Are you sure you want to change the base?
♻️ Clean up legacy code and optimize OpenAPI performance #13874
Conversation
This scope was kept for compatibility but is no longer used by FastAPI. Removing it reduces WebSocket connection overhead.
Add caching mechanism for default_status_code attribute to avoid repeated signature inspection, improving schema generation performance.
Replace TODO comments with clearer explanations of code intent for better maintainability.
Hi 👋 I noticed that the label check failed. Could you please add the appropriate label? This PR is a refactor. ✅ Thanks! |
@gudwls215, thanks for your interest and efforts! In general it's better to split changes that are not related to each other into separate PRs to make it easier to review. |
@@ -520,7 +516,6 @@ def __init__( | |||
# would pass the validation and be returned as is. | |||
# By being a new field, no inheritance will be passed as is. A new model | |||
# will always be created. | |||
# TODO: remove when deprecating Pydantic v1 |
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.
Pydantic v1 is not deprecated yet, why removing TODO?
status_code = str(status_code_param.default) | ||
# Use cached attribute if available, otherwise fall back to inspection | ||
# This improves performance by avoiding repeated signature inspection | ||
if hasattr(current_response_class, "default_status_code"): |
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.
Neither FastAPI, not Starlette have Response.default_status_code
field. How exactly adding this check will affect the performance?
Summary
This PR cleans up legacy code and implements performance optimizations across the FastAPI codebase, addressing several TODO items and improving code maintainability.
Changes Made
🧹 Legacy Code Cleanup
routing.py
): Removed deprecatedfastapi_astack
scope that was kept for compatibility but is no longer used_compat.py
,routing.py
): Updated outdated TODO comments with clearer explanations⚡ Performance Optimizations
openapi/utils.py
): Added caching mechanism fordefault_status_code
attribute to reduce repeated signature inspection overheaddefault_status_code
attribute first before falling back to runtime inspection📚 Code Quality Improvements
Performance Impact
Testing
Related Issues
Addresses technical debt items identified in the contributing guidelines analysis:
Type of Change
Checklist