This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JBernardo
Recipients JBernardo
Date 2013-06-07.17:43:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The configparser.RawConfigParser class implements some `get` methods: 
    get, getint, getfloat, getboolean

but if any of these get overridden on a subclass(with other arguments) or new ones are added (e.g. getlist), there's no way a SectionProxy instance will be able to use them.

    class DemoParser(ConfigParser):
        def getlist(self, section, option):
            return self.get(section, option).split()

    parser = DemoParser()

    # These 2 lines should be equivalent, like "getint", but the
    # second doesn't work because of the SectionProxy instance
    parser.getlist('some_section', 'foo')

Reading the code, for SectionProxy, it redefines all the get* methods from RawConfigParser, and that looks pretty bad...

A more elegant approach would be to fetch the function on the parser instance and bound to the section name with `lambda` or `functools.partial`... Something like:

    class SectionProxy(...):
        def __getattr__(self, attr):
            if not attr.startswith('get'):
                raise AttributeError(attr)
            fn = getattr(self._parser, attr)
            return lambda *args, **kw: fn(self._name, *args, **kw)
Date User Action Args
2013-06-07 17:43:50JBernardosetrecipients: + JBernardo
2013-06-07 17:43:50JBernardosetmessageid: <>
2013-06-07 17:43:50JBernardolinkissue18159 messages
2013-06-07 17:43:49JBernardocreate