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

Use UTF-8 as default encoding #306

Merged
merged 1 commit into from Mar 27, 2021
Merged

Conversation

bbc2
Copy link
Collaborator

@bbc2 bbc2 commented Mar 10, 2021

The default value for the encoding parameter of load_dotenv and dotenv_values is now "utf-8" instead of None (which selected the encoding based on the user's locale). It is passed directly to io.open.

The rationale for this change is that the encoding of a project file like .env should not depend on the user's locale by default. UTF-8 makes sense as the default encoding since it is also used for Python source files. The main drawback is that it departs from open's default value of None for the encoding parameter.

The default value of None was a source of confusion for some users. The Flask and Docker Compose projects already use encoding="utf-8" to enforce the use of UTF-8 and avoid that sort of confusion.

This is a breaking change but only for users with a non-UTF-8 locale and non-UTF-8 characters in their .env files.

Closes #300. Related to issues #205 and #207. Also see PRs #75, #144 and #161 (merged) which suggested using UTF-8.

@theskumar Does this change make sense to you? We initially avoided the breaking change in #161 but I think it could be worth it in the end.

The default value for the `encoding` paramter of `load_dotenv` and
`dotenv_values` is now `"utf-8"` instead of `None` (which selected the
encoding based on the user's locale).  It is passed directly to
`io.open`.

The rationale for this change is that the encoding of a project file
like `.env` should not depend on the user's locale by default.  UTF-8
makes sense as the default encoding since it is also used for Python
source files.  The main drawback is that it departs from `open`'s
default value of `None` for the `encoding` parameter.

The default value of `None` was a source of confusion for some users.
The Flask and Docker Compose projects already use `encoding="utf-8"` to
enforce the use of UTF-8 and avoid that sort of confusion.

This is a breaking change but only for users with a non-UTF-8 locale and
non-UTF-8 characters in their .env files.
@bbc2 bbc2 self-assigned this Mar 10, 2021
@bbc2 bbc2 merged commit b158aa7 into theskumar:master Mar 27, 2021
@bbc2 bbc2 deleted the default-encoding-utf-8 branch March 27, 2021 08:43
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.

UnicodeDecodeError exception occurs when .env file contains Non-ASCII characters on Windows
1 participant