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
♻ Change a dict()
for {}
in fastapi/utils.py
#3138
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3138 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 243 531 +288
Lines 7419 13629 +6210
===========================================
+ Hits 7419 13629 +6210
Continue to review full report at Codecov.
|
📝 Docs preview for commit 8f737f7 at: https://608d2773115ff8084ddb1b76--fastapi.netlify.app |
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.
The commit message should be "Replace empty dict literal with built-in dict function"
You can also specifiy the reason in the body of the commit which should be performance optimization
Description: Performance optimization. Replacing the dict() calls with direct {} statements
8f737f7
to
3a91387
Compare
📝 Docs preview for commit 3a91387 at: https://627e32546e589151aede165c--fastapi.netlify.app |
dict()
for {}
in fastapi/utils.py
Thanks @ShahriyarR! 🚀 Also, don't worry about the commit messages, I update the PR title and squash and merge afterwards, so I take care of keeping the commits consistent with the style of the code. |
In general
dict()
call is considered slower than direct{}
.The internal representations are also different, there is no extra function call while constructing the map with
{}
There are bunch of similar cases in FastAPI source code, I will send PRs accordingly.