You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lambdas = []
for val in range(3):
lambdas.append(lambda val=val: print(val))
for lam in lambdas:
lam()
funcs = []
for val in range(3):
def make_func(val):
def tmp():
return print(val)
return tmp
funcs.append(make_func(val))
for func in funcs:
func()
funcs = []
for val in range(3):
def make_func(val=val):
def tmp():
return print(val)
return tmp
funcs.append(make_func())
for func in funcs:
func()
outputs:
0
1
2
0
1
2
0
1
2
but ruff 0.0.263 reports B023 violations for the make_func variants (because the val variable is shadowed):
falsepositive.py:
12:26 B023 Function definition does not bind loop variable `val`
26:26 B023 Function definition does not bind loop variable `val`
python code:
outputs:
but ruff
0.0.263
reports B023 violations for themake_func
variants (because theval
variable is shadowed):note that the last
make_func
variant might be a common pattern in python codebases, see https://stackoverflow.com/a/3431699The text was updated successfully, but these errors were encountered: