Skip to content

Possible UnicodeError caused by missing encoding="utf-8" #1908

@methane

Description

@methane

def get_py_project_toml(path):
with open(str(path)) as file_handler:
config_data = toml.load(file_handler)

toml must be encoded by UTF-8. Please add encoding="utf-8" here.
It may cause UnicodeDecodeError when pyproject.toml contains non-ASCII character and locale encoding is not UTF-8 (e.g. Windows).

with TemporaryFile("wt") as file:
with redirect_stdout(file):
with redirect_stderr(file):
yield

On Windows, stdout is UTF-8 encoded when it is console (e.g. _WinConsoleIO), but the default encoding of TemporaryFile() is legacy encoding. So UTF-8 is better encoding for this purpose.

This is not a real bug because this function is used only here:

with suppress_output():

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:normalaffects many people or has quite an impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions