pylint-bot / pylint-unofficial

UNOFFICIAL playground for pylint github migration
0 stars 0 forks source link

configparser.get return value gets treated as object instead of string #487

Open pylint-bot opened 9 years ago

pylint-bot commented 9 years ago

Originally reported by: Florian Bruhin (BitBucket: The-Compiler, GitHub: @The-Compiler?)


Since pylint 1.4.2 and astroid 1.3.5, the following snippet:

#!python
import configparser

cp = configparser.ConfigParser()
cp['foo'] = {'bar': 'one,two,three'}

print(cp.get('foo', 'bar').split(','))

gives me Instance of 'object' has no 'split' member (no-member). It worked fine with pylint 1.4.1 and astroid 1.3.4.


pylint-bot commented 9 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


This is an example of why we should have flow control understanding in pylint. In configparser.py, in the .get() implementation, we can find this code:

#!python

        try:
            value = d[option]
        except KeyError:
            if fallback is _UNSET:
                raise NoOptionError(option, section)
            else:
                return fallback

Basically pylint (astroid) is really dumb here and infers all the possible returns, disregarding the if statement and the possiblity that d might raise a KeyError. Hopefully I'll work on flow control after pylint 1.5.

pylint-bot commented 9 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


By the way, I don't know why it worked fine with pylint 1.4.1, but I presume the same inference occurred with it as well.