Skip to content

Accept dictionary default value for env.dict - #76

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

sloria merged 2 commits into
sloria:masterfrom
c-w:accept-dict-default-value

Conversation

@c-w

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

Copy link
Copy Markdown
Contributor

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

sloria commented May 16, 2019

Copy link
Copy Markdown
Owner

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