python-dotenv
python-dotenv copied to clipboard
dotenv_values returns an OrderedDict
From this example the value returned by dotenv_values
is supposed to be a dict, but in reality (python 3.9) the value is of type OrderedDict
:
from dotenv import dotenv_values
config = dotenv_values(".env") # config = {"USER": "foo", "EMAIL": "[email protected]"}
This is what I get:
from dotenv import dotenv_values
config = dotenv_values('.env') # config = OrderedDict([('consumer_key', '****'), ('consumer_secret', '****'), ('access_token', '****'), ('access_secret', '****')])
dict(config) # {'consumer_key': '****', 'consumer_secret': '****', 'access_token': '****', 'access_secret': '****'}
Technically, an OrderedDict is a dict (isinstance(OrderedDict(), dict)
is True
), but I agree this may be confusing.
We used to need the OrderedDict for Python 2, but we don't need it anymore now that we only support Python 3, so I'll look into using a regular dict instead.
One caveat; in Python 3, if using Jupyter iPython kernel, insert ordering of a regular dict is not respected, so OrderedDict is still useful. I experienced this issue recently. Ref: https://gandenberger.org/2018/03/10/ordered-dicts-vs-ordereddict/
While this is probably more an issue of IPython, it should be considered.
I just checked this in a jupyter notebook and it doesn't seem to be an issue anymore. I think with @johnziebro point mute, moving to dict would be reasonable. I haven't seen OrderedDict
in quite a while and was surprised getting one here.