sloria / environs

simplified environment variable parsing
MIT License
1.21k stars 85 forks source link

Inconsistent behavior with `env.list` #298

Closed lucas-bremond closed 10 months ago

lucas-bremond commented 1 year ago

When MY_ENV_VAR is not defined,

env.int("MY_ENV_VAR", default=None)

returns None (as expected), but:

env.list("MY_ENV_VAR", subcast=str, default=None)

yields the following Exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/environs/__init__.py", line 122, in method
    value = preprocess(value, **preprocess_kwargs)
  File "/usr/local/lib/python3.10/site-packages/environs/__init__.py", line 206, in _preprocess_list
    return typing.cast(str, value).split(delimiter) if value != "" else []
AttributeError: 'NoneType' object has no attribute 'split'

I believe the second example should return None as well.

Thoughts?

sloria commented 10 months ago

thanks for reporting this! this is fixed in #316