configparser: BasicInterpolation raises TypeError interpolating a value-less option
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
With allow_no_value=True and the default BasicInterpolation, interpolating a reference to a value-less option raises TypeError instead of resolving or raising a configparser error. ExtendedInterpolation treats the missing value as empty in the same situation.
import configparser
cfg = configparser.ConfigParser(allow_no_value=True)
cfg.read_string("[s]\na\nb = x%(a)sy\n")
cfg.get("s", "b")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cfg.get("s", "b")
~~~~~~~^^^^^^^^^^
File "../Lib/configparser.py", line 855, in get
return self._interpolation.before_get(self, section, option, value,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
d)
^^
File "../Lib/configparser.py", line 433, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "../Lib/configparser.py", line 474, in _interpolate_some
if "%" in v:
^^^^^^^^
TypeError: argument of type 'NoneType' is not a container or iterable
The same pattern with ExtendedInterpolation (b = x${s:a}y) returns "xy".
ExtendedInterpolation._interpolate_some guards this (if v is None: continue, added in gh-130941); BasicInterpolation._interpolate_some does not and reaches if "%" in v: with v set to None (Lib/configparser.py).
Observed on 3.16.0a0.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-153857
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Lib/configparser.py at BasicInterpolation._interpolate_some and compare its handling with ExtendedInterpolation._interpolate_some, as described in the report. Confirm the value-less option case no longer raises TypeError and follows the intended interpolation behavior; linked PR gh-153857 indicates the work is already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100