Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept dictionary default value for env.dict #76

Merged
merged 2 commits into from
May 16, 2019
Merged

Accept dictionary default value for env.dict #76

merged 2 commits into from
May 16, 2019

Conversation

c-w
Copy link
Contributor

@c-w c-w commented May 15, 2019

Currently, env.list accepts a list default value, so the following code works:

>>> my_list = env.list("LIST", ["1", "2"])

However, env.dict does not accept a dict default value, so the following code crashes:

>>> my_dict = env.dict("DICT", {"key1": "1", "key2": "2"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../site-packages/environs.py", line 54, in method
    value = preprocess(value, subcast=subcast, **kwargs)
  File ".../site-packages/environs.py", line 114, in _preprocess_dict
    for key, val in (item.split("=") for item in value.split(",") if value)
AttributeError: 'dict' object has no attribute 'split'

This lack of similarity between the APIs is somewhat confusing, so this pull request proposes a change that makes env.dict accept a dictionary as default argument.

@sloria
Copy link
Owner

sloria commented May 16, 2019

Thanks!

@sloria sloria merged commit 4735a40 into sloria:master May 16, 2019
@c-w c-w deleted the accept-dict-default-value branch May 16, 2019 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants