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

Inconsistency with os.environ and str/unicode in Python 2 #176

Closed
bbc2 opened this issue May 4, 2019 · 3 comments · Fixed by #177
Closed

Inconsistency with os.environ and str/unicode in Python 2 #176

bbc2 opened this issue May 4, 2019 · 3 comments · Fixed by #177

Comments

@bbc2
Copy link
Collaborator

bbc2 commented May 4, 2019

In Python 2, os.environ is a map with str keys and str values, not unicode. Unfortunately, values loaded with Python-dotenv are unicode.

Example with test.py:

import os

import dotenv

dotenv.load_dotenv()
print(type(os.environ["foo"]))

and .env:

foo=bar

Results:

> python test.py
<type 'unicode'>
> env foo=bar python test.py
<type 'str'>

I think that it's probably not worth fixing given Python 2's upcoming end of life, but I'm pointing this out here because this might justify turning off some Mypy type warnings for Python 2.

@bbc2
Copy link
Collaborator Author

bbc2 commented May 4, 2019

Apparently, this was fixed on Windows thanks to #101, but that fix probably accidentally went away with later MRs.

@bbc2
Copy link
Collaborator Author

bbc2 commented May 4, 2019

this might justify turning off some Mypy type warnings for Python 2

Actually, that's a terrible idea! I just found a bug with Unicode and Python 2 hidden behind a # type: ignore. To be more precise, this bug is fairly recent (version 0.10.0) whereas the str/unicode inconsistency pointed out in this issue has existed for a long time (at least since version 0.9.0). I'll open a separate issue.

@theskumar
Copy link
Owner

Released the fix in v0.10.2, thanks! 🎉

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 a pull request may close this issue.

2 participants