Preciso usar uma variável iterável e uma variável de loop como propriedade de classe. Mas o verificador flake8 gera o aviso B2020:
easy.py:11:13: B020 Found for loop that reassigns the iterable it is iterating with each iterable value.
Se eu usar uma variável para iterável, está tudo bem.
O que está errado?
O exemplo de advertência:
#!/usr/bin/env python3
"""Example of B020 error."""
class My_Template:
"""My example."""
def __init__(self, *template):
"""Obviously init."""
self.all_templates = (1, 2, 3)
for self.tpl in self.all_templates:
print(self.tpl)
O flake8 reclama sobre a variável de loop:
easy.py:11:13: B020 Found for loop that reassigns the iterable it is iterating with each iterable value.
O exemplo OK:
#!/usr/bin/env python3
"""Example of B020 error."""
class My_Template:
"""My example."""
def __init__(self, *template):
"""Obviously init."""
all_templates = (1, 2, 3)
for self.tpl in all_templates:
print(self.tpl)