-
-
Notifications
You must be signed in to change notification settings - Fork 60
Check whether the return value from RateLimit.from_http() is None
#207
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: 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 <[email protected]>
|
@brettcannon Thanks, added the suggestion! |
brettcannon
left a comment
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. |
|
@Kjeld-P still interested in updating your PR with unit tests as requested? |
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 returnTrueifself.remaining > 0, which would not be the case if the rate-limit was indeed exceeded.The proposed fix simply explicitly checks if the returned
RateLimitobject is notNone.