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)
It seems the python2.7
linter cannot figure out that this attribute is a dict.
python3 -m pylint file.py
produces no such error. So it seems there's something specific to python2.7
that's causing the linter to fail.
I did some further playing around and saw that if I remove the (frozen=True)
(which I believe makes Daily
instances immutable after instantiation), the linter error seems to disappear. Not sure why that would change anything
If I remove the base class, and just do
file.py
:
from daily import Daily
class MyClass:
def set_ids(self, args):
if id not in self.daily.obj_dict:
print("testing")
def process(self, vals, ids):
obj_dict = {
id: vals[id]
for id in ids
}
self.daily = Daily(obj_dict)
there does not appear to be this lint error