Skip to content

Conversation

@rhcarvalho
Copy link
Contributor

@rhcarvalho rhcarvalho commented Jun 22, 2020

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.

@rhcarvalho rhcarvalho requested a review from untitaker June 22, 2020 08:19
hub = Hub.current
if hub is not None:
hub.scope.set_tag(key, value)
return Hub.current.scope.set_tag(key, value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@rhcarvalho rhcarvalho force-pushed the rhcarvalho/hub-current-never-none branch from eef298a to b716342 Compare June 22, 2020 10:44
@rhcarvalho
Copy link
Contributor Author

Removed now unused import

from contextlib import contextmanager

@rhcarvalho rhcarvalho merged commit 8aecc71 into master Jun 22, 2020
@rhcarvalho rhcarvalho deleted the rhcarvalho/hub-current-never-none branch June 22, 2020 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants