diff --git a/environs/__init__.py b/environs/__init__.py index 95ad1d2..0e69db4 100644 --- a/environs/__init__.py +++ b/environs/__init__.py @@ -136,7 +136,9 @@ def _make_list_field(*, subcast: typing.Optional[type], **kwargs) -> ma.fields.L def _preprocess_list(value: typing.Union[str, typing.Iterable], **kwargs) -> typing.Iterable: - return value if ma.utils.is_iterable_but_not_string(value) else typing.cast(str, value).split(",") + if ma.utils.is_iterable_but_not_string(value): + return value + return typing.cast(str, value).split(",") if value != "" else [] def _preprocess_dict( diff --git a/tests/test_environs.py b/tests/test_environs.py index 5e525eb..15b3e00 100644 --- a/tests/test_environs.py +++ b/tests/test_environs.py @@ -81,6 +81,11 @@ def test_list_with_subcast(self, set_env, env): assert env.list("LIST", subcast=int) == [1, 2, 3] assert env.list("LIST", subcast=float) == [1.0, 2.0, 3.0] + def test_list_with_empty_env_and_subcast(self, set_env, env): + set_env({"LIST": ""}) + assert env.list("LIST", subcast=int) == [] + assert env.list("LIST", subcast=float) == [] + def test_bool(self, set_env, env): set_env({"TRUTHY": "1", "FALSY": "0"}) assert env.bool("TRUTHY") is True