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
Bug report
Bug description:
With
allow_no_value=Trueand the defaultBasicInterpolation, interpolating a reference to a value-less option raisesTypeErrorinstead of resolving or raising a configparser error.ExtendedInterpolationtreats the missing value as empty in the same situation.The same pattern with
ExtendedInterpolation(b = x${s:a}y) returns"xy".ExtendedInterpolation._interpolate_someguards this (if v is None: continue, added in gh-130941);BasicInterpolation._interpolate_somedoes not and reachesif "%" in v: with vset toNone(Lib/configparser.py).Observed on 3.16.0a0.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs