-
Notifications
You must be signed in to change notification settings - Fork 107
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
False positive B023
with loop's local variable
#402
Comments
In your example it doesn't matter because |
Thanks for the response, just trying to understand it more. The below code with def some_fn(fn) -> None:
print(fn())
foo = 0
for _ in range(10):
foo = foo + 1 # foo is a local variable in the loop iteration
some_fn(lambda: foo) Would you mind clarifying your example? I am trying to understand the line between false positive and true positive here. Also, if you think this issue should be closed out, feel free to close it |
If the function invocation is delayed (for whatever reason) you'd get an unexpected behaviour. foo = 0
fns = []
for _ in range(10):
foo = foo + 1
fns.append(lambda: print(foo))
for fn in fns:
fn() # all print 10 I suppose it would be pretty hard to verify if the lambda is only invoked within the same iteration |
Since
foo
is a local variable in the loop,B023
shouldn't happen here (unless I am mistaken about something).Running
flake8==6.0.0
withflake8-bugbear==23.7.10
on this:I think this relates to #269 or #380.
The text was updated successfully, but these errors were encountered: