diff --git a/donfig/config_obj.py b/donfig/config_obj.py index 7ae34c4..738ac7f 100644 --- a/donfig/config_obj.py +++ b/donfig/config_obj.py @@ -415,7 +415,9 @@ def __init__( *[os.path.join(prefix, "etc", name) for prefix in site.PREFIXES], os.path.join(os.path.expanduser("~"), ".config", name), ] - + else: + # copy so the env-var append below never mutates the caller's list + paths = list(paths) if env_prefix is None: env_prefix = f"{name.upper()}_" if env is None: diff --git a/donfig/tests/test_config.py b/donfig/tests/test_config.py index c5148bd..2e5254e 100644 --- a/donfig/tests/test_config.py +++ b/donfig/tests/test_config.py @@ -606,6 +606,21 @@ def test__get_paths(monkeypatch): assert len(paths) == len(set(paths)) +def test_paths_not_mutated(monkeypatch): + monkeypatch.setenv("MYPKG_CONFIG", "foo-bar") + paths = ["/etc/mypkg"] + config = Config("mypkg", paths=paths) + assert config.paths == ["/etc/mypkg", "foo-bar"] + # the caller's list is copied on init, not aliased + assert paths == ["/etc/mypkg"] + + +def test_paths_accepts_any_sequence(monkeypatch): + monkeypatch.setenv("MYPKG_CONFIG", "foo-bar") + config = Config("mypkg", paths=("/etc/mypkg",)) + assert config.paths == ["/etc/mypkg", "foo-bar"] + + def test_serialization(): config = Config(CONFIG_NAME) config.set(one_key="one_value")