How To Avoid Pylint Not-an-iterable When Using A Custom Property Class
My code uses the commonly used cached_property class from werkzeug. Consider the following snippet: from werkzeug import cached_property class SampleClass(object): @cached_pro
Solution 1:
Looks like you are importing cached_property
incorrectly. It lives in werkzeug.utils
. pylint
caught that error: E: 1, 0: No name 'cached_property' in module 'werkzeug' (no-name-in-module)
. Here's the fixed code:
from werkzeug.utils import cached_property
class SampleClass(object):
@cached_property
def list_prop(self):
return [1, 2]
sample = SampleClass()
for item in sample.list_prop:
print item
When I run pylint
after applying this fix, it stops complaining:
$ pylint test
No config file found, using default configuration
************* Module test
C: 1, 0: Missing module docstring (missing-docstring)
C: 3, 0: Missing class docstring (missing-docstring)
C: 5, 4: Missing method docstring (missing-docstring)
R: 3, 0: Too few public methods (1/2) (too-few-public-methods)
C: 8, 0: Invalid constant name "sample" (invalid-name)
Solution 2:
I face the same problem when I use the Django+ pylint : the code is as follows:
queryset = A.objects.filter(col_a='a',col_b='b')
It will show error message:
Non-iterable value queryset is used in an iterating context (not-an-iterable)
My solution is as follows(+all()):
queryset = A.objects.filter(col_a='a',col_b='b').all()
It actually solved my problem, I know it seems has no much related to the issue but I google 'pylint + Non-iterable', this page will be on the top of search result, so I want to put the solution here,thanks
Post a Comment for "How To Avoid Pylint Not-an-iterable When Using A Custom Property Class"