jucacrispim / pylint-mongoengine

Pylint plugin to handle mongoengine stuff
GNU General Public License v3.0
15 stars 6 forks source link

Suppress 'Not an iterable' errors when accessing fields of the appropriate types #7

Closed macdjord closed 5 years ago

macdjord commented 5 years ago

When I lint my MongoEngine docs, I constantly get warnings about non-iterable values being used in an iterable context when I'm iterating over list fields. It would be very nice if those messages could be suppressed for fields which are, in fact, iterable.

jucacrispim commented 5 years ago

Sorry for the delay, man. I've been really busy lately. Again, I coudn't reproduce the error. Can you provide a piece of code showing the error?

Thank you very much!

macdjord commented 5 years ago
import mongoengine as _me

class Test(_me.Document):
    map_field = _me.MapField(_me.StringField)

    def do_stuff(self):
        # E1135: Value 'self.map_field' doesn't support membership test (unsupported-membership-test)
        if 'toto' in self.map_field:
            pass

        # E1133: Non-iterable value self.map_field is used in an iterating context (not-an-iterable)
        for k in self.map_field:
            pass

        # E1137: 'self.map_field' does not support item assignment (unsupported-assignment-operation)
        self.map_field['foo'] = 'bar'

        # E1138: 'self.map_field' does not support item deletion (unsupported-delete-operation)
        del self.map_field['baz']
jucacrispim commented 5 years ago

Thank you very much!

It is fixed on master and I've released pylint-mongoengine==0.3.3 to PyPI.