-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Check whether the return value from RateLimit.from_http()
is None
#207
base: main
Are you sure you want to change the base?
Conversation
Check if rate_limit is a valid object rather than evaluating it as a bool when deciding whether to raise a RateLimit exception or not,
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #207 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 9 9
Lines 471 471
Branches 87 87
=========================================
Hits 471 471 ☔ View full report in Codecov by Sentry. |
RateLimit.from_http()
is None
You're right about the bug! Slight code tweak to your PR and it's failing linting. |
Co-authored-by: Brett Cannon <brett@python.org>
@brettcannon Thanks, added the suggestion! |
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.
I just realized there isn't a test for this. 😅 Could you add one?
We also need the changelog entry for this bug fix. |
In handling error-responses from the server the code checks if it's possible to create a rate limit object from the headers through
RateLimit.from_http(headers)
. This function returns an object if rate limit info was found, and None otherwise.The next line of code wants to check if this value was not none, but does not do so explicitly:
if rate_limit
. This causes python to evaluate it as a boolean and callRateLimit.__bool__
. This will only returnTrue
ifself.remaining > 0
, which would not be the case if the rate-limit was indeed exceeded.The proposed fix simply explicitly checks if the returned
RateLimit
object is notNone
.