Approve functions used as default arguments #4699
Merged
Conversation
14 tasks
dhruvmanila
requested changes
Aug 31, 2021
If this is intended, assign the function call to a module-level variable and use that variable as a default value.
Why don't we do what the linter is suggesting us to? I hate adding ignore directives throughout the code. If not, then we should atleast explain in a comment as to why that directive was added.
The default value for **seed** is the result of a function call which is not normally recommended and causes flake8-bugbear to raise a B008 error. However, in this case, it is accptable because `LinearCongruentialGenerator.__init__()` will only be called once per instance and it ensures that each instance will generate a unique sequence of numbers.
The default value for **backend** is the result of a function call which is not normally recommended and causes flake8-bugbear to raise a B008 error. However, in this case, it is accptable because `Aer.get_backend()` is called when the function is definition and that same backend is then reused for function calls.
dhruvmanila
approved these changes
Aug 31, 2021
I think the explanation should be a comment instead of adding in a docstring as it is intended only for developers instead of end-users, otherwise LGTM.
Comment above function definition or below? If below, before docstring or after? |
Above the directive which means above the function definition. |
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.
Describe your change:
Use linter directive
# noqa: B0008
for these functions because they set a seed value andBaseBackend
is reused across all calls andLinearCongruentialGenerator.__init__()
is only called once for each instance.flake8-bugbear B008 Do not perform function calls in argument defaults. The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time function call. If this is intended, assign the function call to a module-level variable and use that variable as a default value.
Checklist:
Fixes: #{$ISSUE_NO}
.The text was updated successfully, but these errors were encountered: