Skip to content
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

Simplify (request.cookies.)getlist function #2838

Merged
merged 6 commits into from
Jun 23, 2024
Merged

Conversation

Tronic
Copy link
Member

@Tronic Tronic commented Oct 14, 2023

Removes a default value in case no matches were found, in which case it previously defaulted to None. Instead, return an empty list which is more sensible in this case as the return value will then always be a list.

Presumably practically no-one uses this functionality, and Pythonic tests if None and if [] are equal. In case you do need a default value, there is an easy and a more efficient alternative because the fallback value after or is only constructed if needed and not in any case:

list_of_foo = request.cookies.getlist("foo") or ["my", "default", "value"]

… none are found. Previously it defaulted to returning `None`. Instead return an empty list which is sensible and avoids ambiguity with return types.
@Tronic Tronic requested a review from a team as a code owner October 14, 2023 19:30
@codecov
Copy link

codecov bot commented Oct 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.463%. Comparing base (fcbd747) to head (4cc9166).
Report is 1 commits behind head on main.

Current head 4cc9166 differs from pull request most recent head c806362

Please upload reports for the commit c806362 to get more accurate results.

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2838       +/-   ##
=============================================
- Coverage   87.617%   87.463%   -0.154%     
=============================================
  Files          101       101               
  Lines         7575      7626       +51     
  Branches      1329      1340       +11     
=============================================
+ Hits          6637      6670       +33     
- Misses         641       658       +17     
- Partials       297       298        +1     

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

ahopkins
ahopkins previously approved these changes Jun 23, 2024
@ahopkins ahopkins merged commit 39d4ea4 into main Jun 23, 2024
25 checks passed
@ahopkins ahopkins deleted the remove-getlist-fallback branch June 23, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants