TypeError when playing with examples

16 views
Skip to first unread message

Jan Hutař

unread,
Feb 14, 2008, 10:02:54 AM2/14/08
to iniparse-discuss
Hello,
I have tried examples from UsageExamples and am getting this error:



Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from iniparse import ConfigParser
>>> cfgpr = ConfigParser()
>>> cfgpr.read('/home/pok/Checkouts/tests/python-iniparse/simple/options.ini')
['/home/pok/Checkouts/tests/python-iniparse/simple/options.ini']
>>> cfgpr.get('ui', 'width')
'150'
>>> cfgpr.set('ui', 'width', 175)
>>> cfgpr.get('ui', 'width')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/iniparse/compat.py", line
224, in get
return self._interpolate(section, option, value, d)
File "/usr/lib/python2.5/site-packages/iniparse/compat.py", line
232, in _interpolate
if "%(" in value:
TypeError: argument of type 'int' is not iterable



I have created 2 patches which fixes this, but both causes at least 1
unit test to fail:

* with int-not-iterable-get.patch these unit-tests fails:

tests.test_compat.ConfigParserTestCase

* with int-not-iterable-set.patch these unit-tests fails:

tests.test_compat.RawConfigParserTestCase
tests.test_compat.ConfigParserTestCase

I do not have a clue which of them is better. Please could you review
them and provide some feedback on this issue?

Paramjit Oberoi

unread,
Feb 14, 2008, 1:25:27 PM2/14/08
to iniparse...@googlegroups.com
Hi Jan,

Thanks for pointing this out. This looks like a bug at first glance.
I'll take a look at your patches in the next couple of days and post a
message here when I know more.

-param

Paramjit Oberoi

unread,
Feb 19, 2008, 12:34:13 PM2/19/08
to iniparse...@googlegroups.com
OK, I looked into this, and unfortunately, this is expected behavior.
Python's ConfigParser class behaves the same way, and the Python test
suite has tests to check for this. See the test
ConfigParserTestCase.test_set_nonstring_types in
test/test_cfgparser.py in the standard library.

As a workaround, you can pass "raw=True" to get() to turn off the
interpolation, which will eliminate the error.

I'll fix the usage examples to not use an int.

Jan Hutař

unread,
Feb 21, 2008, 6:40:27 AM2/21/08
to iniparse-discuss
I see, thank you for investigating this.
Reply all
Reply to author
Forward
0 new messages