Skip to content

Accept dictionary default value for env.dict#76

Merged
sloria merged 2 commits intosloria:masterfrom
c-w:accept-dict-default-value
May 16, 2019
Merged

Accept dictionary default value for env.dict#76
sloria merged 2 commits intosloria:masterfrom
c-w:accept-dict-default-value

Conversation

@c-w
Copy link
Copy Markdown
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
Copy Markdown
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