Last active
November 6, 2017 01:10
-
-
Save moylop260/ec534248e35ab193a84501b8fd96b1fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
def method_from_odoo(meth): | |
print(meth()) # Good case if it was used one time and is not used anymore. | |
MY_LIST = [] | |
def method_pylint_think_is_used(meth): | |
MY_LIST.append(meth) # Wrong case if it is stored to use after. | |
def cases(): | |
"""Closing over a loop variable.""" | |
for i in range(10): | |
method_from_odoo(lambda: i) | |
method_pylint_think_is_used(lambda: i) | |
cases() | |
# bad case if you use the meth after, because it will have the same value in all lambda methods. | |
print([meth() for meth in MY_LIST]) | |
# Results: | |
# 0 | |
# 1 | |
# 2 | |
# 3 | |
# 4 | |
# 5 | |
# 6 | |
# 7 | |
# 8 | |
# 9 | |
# [9, 9, 9, 9, 9, 9, 9, 9, 9, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment