Skip to content

configparser throws TypeError for combination of interpolation and allow_no_value #130941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dabuahoid opened this issue Mar 7, 2025 · 0 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dabuahoid
Copy link

dabuahoid commented Mar 7, 2025

Bug report

Bug description:

The configparser modules throws an Exception as:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    config.get("dummy", "b")
  File "python3.12/configparser.py", line 777, in get
    return self._interpolation.before_get(self, section, option, value,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.12/configparser.py", line 428, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
  File "python3.12/configparser.py", line 481, in _interpolate_some
    if "$" in v:
       ^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

when using:

config.ini

[dummy]
a
b = ${a}

and following ConfigParser settings:

test.py

import configparser
config = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation(), allow_no_value=True)
config.read("config.ini")
config.get("dummy", "b")

Since the value of a is None the interpolation should convert the reference first to an empty string to keep interpolation alive.
Expected value for b would be an empty string.

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux, Windows

Linked PRs

@dabuahoid dabuahoid added the type-bug An unexpected behavior, bug, or error label Mar 7, 2025
@ZeroIntensity ZeroIntensity added the stdlib Python modules in the Lib dir label Mar 7, 2025
sobolevn added a commit to sobolevn/cpython that referenced this issue Mar 7, 2025
ambv pushed a commit that referenced this issue Apr 16, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 16, 2025
…ue` and `interpolation` set (pythonGH-130949)

(cherry picked from commit c35c735)

Co-authored-by: sobolevn <[email protected]>
ambv pushed a commit that referenced this issue Apr 16, 2025
…lue` and `interpolation` set (GH-130949) (#132588)

gh-130941: Fix `configparser` parsing values with `allow_no_value` and `interpolation` set (GH-130949)
(cherry picked from commit c35c735)

Co-authored-by: sobolevn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants