ref: Remove Hub.current is not None checks#727
Merged
rhcarvalho merged 1 commit intomasterfrom Jun 22, 2020
Merged
Conversation
untitaker
approved these changes
Jun 22, 2020
rhcarvalho
commented
Jun 22, 2020
| hub = Hub.current | ||
| if hub is not None: | ||
| hub.scope.set_tag(key, value) | ||
| return Hub.current.scope.set_tag(key, value) |
Contributor
Author
There was a problem hiding this comment.
As noted in the PR description / commit message, I intentionally decided to always use the pattern return Hub.current.method(...), even when the return value is None. The idea behind it is to avoid accidentally returning None when the Hub method returns something else (e.g. as part of a behavior change). In other words, I find this easier to maintain than to selectively use or not the return keyword.
By construction, Hub.current is never None, such that the expression
Hub.current is not None
always evaluates to True.
This commit simplifies all uses of Hub.current, and in particular
chooses to write "return Hub.current.method(...)" for every method, even
when the method returns None. The intent is to make it easier to keep
the static API matching the Hub behavior. Without this, if a method
returns anything other than None the static API would silently drop it,
leading to unnecessary debugging time spent trying to identify the
culprit.
eef298a to
b716342
Compare
Contributor
Author
|
Removed now unused import from contextlib import contextmanager |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By construction, Hub.current is never None, such that the expression
always evaluates to True.
This commit simplifies all uses of Hub.current, and in particular
chooses to write
return Hub.current.method(...)for every method, evenwhen the method returns None. The intent is to make it easier to keep
the static API matching the Hub behavior. Without this, if a method
returns anything other than None the static API would silently drop it,
leading to unnecessary debugging time spent trying to identify the
culprit.