0

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?

jinkins
  • 25
  • 1
  • 6
  • You probably need some kind of plugin. Statically speaking, `obj_dict` isn't iterable; only the value ultimately assigned to the attribute by way of `attr.s` is. – chepner Feb 23 '23 at 15:53
  • As far as `pylint` is concerned, `obj_dict` is a class attribute with some non-iterable value. – chepner Feb 23 '23 at 16:02
  • @chepner But then why does `pylint` no longer give the same error if I remove the base class (see linked post) or if I removed the `frozen=True`? Why does it suddenly no longer think that `obj_dict` is some non-iterable value? – jinkins Feb 23 '23 at 16:05

0 Answers0