Skip to content

Commit

Permalink
check PYTHONWARNDEFAULTENCODING
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Dec 20, 2024
1 parent cb6b560 commit 412c18b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/monty/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ def zopen(
stacklevel=2,
)

# Warn against default `encoding` in text mode
if "t" in mode and kwargs.get("encoding", None) is None:
# Warn against default `encoding` in text mode if `PYTHONWARNDEFAULTENCODING` is set
if (
os.getenv("PYTHONWARNDEFAULTENCODING", False)
and "t" in mode
and kwargs.get("encoding", None) is None
):
warnings.warn(
"We strongly encourage explicit `encoding`, "
"and we would use UTF-8 by default as per PEP 686",
Expand Down

0 comments on commit 412c18b

Please sign in to comment.