Re: [PATCH v2] kconfig: tests: avoid mutating extra_env dicts in Conf

From: Julian Braha

Date: Fri Dec 04 2026 - 09:30:00 EST


On 12/4/26 10:26, Pavee Zheng via B4 Relay wrote:
> From: Pavee Zheng <pavee.zheng@xxxxxxxxx>
>
> Ruff's B006 (mutable-argument-default) lint flags using mutable data
> structures such as {} as default argument values because Python
> evaluates default arguments once at function definition time and shares
> the same object across all calls, so in-place mutations persist across
> subsequent calls.
>
> Conf._run_conf() and Conf._allconfig() both declare extra_env={} and
> mutate extra_env in place:
>
> - Conf._allconfig() assigns extra_env['KCONFIG_ALLCONFIG'] when
> all_config is set. No existing test currently passes a non-None
> all_config to allyesconfig(), allmodconfig(), allnoconfig(), or
> alldefconfig(), so this does not trigger a failure today, but a
> future caller doing so would leave a stale KCONFIG_ALLCONFIG entry
> in the shared default dictionary for subsequent calls in the same
> pytest session.
> - Conf._run_conf() assigns extra_env['srctree'], mutating both its
> default dictionary and caller-owned dictionaries passed via
> extra_env (such as warn_changed_input in
> scripts/kconfig/tests/warn_changed_input/__init__.py).
>
> As a defensive cleanup and readability improvement, default extra_env
> to None in both methods. In _run_conf(), merge extra_env into the local
> env dictionary and set env['srctree'] there instead of mutating
> extra_env. In _allconfig(), build a fresh local dictionary copy before
> inserting KCONFIG_ALLCONFIG.
>
> Signed-off-by: Pavee Zheng <pavee.zheng@xxxxxxxxx>
Tested-by: Julian Braha <julianbraha@xxxxxxxxx>
Reviewed-by: Julian Braha <julianbraha@xxxxxxxxx>

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature