Skip to content

ExtendedInterpolation drops get() vars overrides during recursive interpolation #158698

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: RawConfigParser.get documentation in the module docstring: "Additional substitutions may be provided using the vars argument, which must be a dictionary whose contents override any pre-existing defaults."

Expected: override

Actual: original

import configparser

section, b, v = "s", "original", "override"
options = {"x": "${y}", "y": "${z}", "z": b}
overrides = {"z": v}
data = {"section": section, "b": b, "v": v, "vars": overrides}

p = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
if section == p.default_section or not isinstance(overrides, dict) or any(
    not isinstance(s, str) or "$" in s for s in (b, v)
):
    print("REFUTATION REJECTED:", "invalid input")
else:
    p.read_dict({section: options})
    actual = p.get(section, "x", vars=overrides)
    substitutions = dict(options, **overrides)
    expected = substitutions["x"]
    while expected.startswith("${") and expected.endswith("}"):
        expected = substitutions[expected[2:-1]]
    if actual != expected:
        print("REFUTATION CONFIRMED:", data, "actual =", repr(actual),
              "expected =", repr(expected))
    else:
        print("REFUTATION REJECTED:", "actual matches documented expectation")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library configparser:

REFUTATION CONFIRMED: {'section': 's', 'b': 'original', 'v': 'override', 'vars': {'z': 'override'}} actual = 'original' expected = 'override'

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/configparser-20261003-021945-c1

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions