-
Notifications
You must be signed in to change notification settings - Fork 821
Raising AssertionErrors instead of assert statements #794
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
Conversation
@@ -44,8 +44,10 @@ def get_complete_version(version=None): | |||
if version is None: | |||
from graphene import VERSION as version | |||
else: | |||
assert len(version) == 5 |
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 suggest only using is
for comparing versus None, or identity comparisons. ==
is for comparing logical equivalence, which is going to be pretty much all numeric comparisons.
Some of the answers on https://stackoverflow.com/questions/2239737/is-it-better-to-use-is-or-for-number-comparison-in-python discuss it a bit more (1st SO page I googled).
graphene/relay/connection.py
Outdated
"Resolved value from the connection field have to be iterable or instance of {}. " | ||
'Received "{}"' | ||
).format(connection_type, resolved) | ||
if not isinstance(resolved, Iterable): |
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.
Rather than repeating the construction:
if BOOLEAN_EXPRESSION:
raise AssertionError("...")
Could you DRY things up by writing a helper function that does this and use it across the code as a straight replacement for the assert
statements?
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 am trying to do something like this -
def raise_assertion_if(condition=None, message=None):
if condition:
raise AssertionError(message)
raise_assertion_if(
condition=version[3] not in ("alpha", "beta", "rc", "final"),
message="Release version is unkown"
)
But, Black (linter) keeps failing. Any clue as to why?
Closed. This was resolved in #808 |
Code to use
instead of
assert something is not None, "Something was unexpectedly None"