This question arises from my question (Value [dict object] doesn't support membership test) yesterday, where using pylint
with python2.7
is unable to recognize that an object is iterable.
I'll copy and paste the code from the above post here:
file.py
import attr
from base import BaseClass
@attr.s
class MyClass(BaseClass):
def set_ids(self, args):
if id not in self.daily.obj_dict:
# do some stuff
print("testing")
base.py
:
from abc import ABCMeta, abstractmethod
from six import with_metaclass
from daily import Daily
class BaseClass(with_metaclass(ABCMeta, object)):
@abstractmethod
def set_ids(self, args):
pass
def process(self, vals, ids):
obj_dict = {
id: vals[id]
for id in ids
}
self.daily = Daily(obj_dict)
daily.py
:
import attr
from builtins import object
@attr.s(frozen=True)
class Daily(object):
obj_dict = attr.ib(default=None)
python2.7 -m pylint file.py
produces the error
E: 8,17: Value 'self.daily.obj_dict' doesn't support membership test (unsupported-membership-test)
I need to figure out how to silence this error, and I was thinking I could somehow tell the linter it's a dict
or iterable type. How can I do this in python2.7
?