Question

I am new to pylint. I ran the following through pylint and get an error where I try to iterate through a dictionary:

"ID:maybe-no-member Instance of 'bool' has no 'iteritems' member (but some types could not be 
 inferred)"

This is a Flask app and I pass a json-encoded dictionary via AJAX to '/my_endpoint/'. I then need to iterate through that dictionary and do some stuff.

@app.route('/my_endpoint/')
def my_endpoint():
    """My Description"""
    try:
        my_params = json.loads(request.args.get('names'))
    except TypeError:
        my_params = None

    if my_params is not None:
        for key,value in my_params.iteritems(): # error occurs here
            ...

Attempts to google the error don't result in any description of what the error means nor any solutions. Thanks!

Was it helpful?

Solution

I suspect (and this is a wild guess) Pylint is complaining because json.loads could return a bool, if asked to decode a string like "false". And the resulting bool would in fact not have a method named iteritems.

But then neither would a string or a list or a number, so I don't know why it's picking on bool. Maybe because it comes first alphabetically among all the possible types.

Does an explicit isinstance(my_params, dict) check make it happy?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top