NoOptionError not being raised

Issue #15 invalid
Charles Morton
created an issue

NoOptionError is not being raised when I try to get the value from a key that is not in the INI file. The following code snippet will hopefully demonstrate the problem. What happens for me is that the value for "bar" is set to None, instead of raising the error. I have the same problem if I read the values from an INI file.

I am running Python 2.7.12 and configparser 3.5.0, and installed configparser using Anaconda. Sorry in advance if I missed something really obvious or this is the expected behavior!

from backports import configparser

parser = configparser.ConfigParser()
foo = 10

# This works
print('foo', parser['options'].get('foo'))

# I thought this would raise a NoOptionError, but instead returns None
print('bar', parser['options'].get('bar'))

Comments (3)

  1. Charles Morton reporter

    I get the exact same result with the built-in configparser in Python 3, so I guess this isn't a bug. If I use the dictionary notation of parser['options']['bar'], I get a KeyError, so that will work.

  2. Log in to comment