danvk
danvk

Reputation: 16945

Can voluptuous code pass pylint?

I run pylint -E as part of the tests on my Python project to ensure that errors don't creep into untested code. Generally this works quite well. But recently I've been running into problems with voluptuous and pylint.

The problem is that pylint thinks that the values returned by voluptuous Schemas are lists, which is simply not the case. Here's a toy program:

import voluptuous

MyType = voluptuous.Schema({
    'q': str
})


def foo(bar):
    bar = MyType(bar)
    q = bar.get('q')
    print q


foo({'q': '1324'})

It runs just fine:

$ python toy.py
1234

pylint, however, flags the .get() call:

$ pylint -E toy.py
No config file found, using default configuration
************* Module toy
E: 11, 8: Instance of 'list' has no 'get' member (no-member)

How can I get this program to pass pylint -E?

Upvotes: 2

Views: 222

Answers (1)

danvk
danvk

Reputation: 16945

One option is to ignore the voluptuous module entirely, e.g.

$ pylint -E --ignored-modules=voluptuous toy.py
(passes)

If would be nice if pylint understood voluptuous better, though.

Upvotes: 1

Related Questions