Skip to content

Commit

Permalink
[#137] Fix error when list with empty env var and subcast (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabdouni authored Mar 22, 2020
1 parent 1a4adbf commit d8f75d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion environs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_environs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8f75d7

Please sign in to comment.