diff --git a/nbqa/replace_source.py b/nbqa/replace_source.py index 23d8c728..1414c922 100644 --- a/nbqa/replace_source.py +++ b/nbqa/replace_source.py @@ -157,7 +157,7 @@ def mutate(python_file: "Path", notebook: "Path", notebook_info: NotebookInfo) - notebook_info Information about notebook cells used for processing """ - notebook_json = json.loads(notebook.read_text()) + notebook_json = json.loads(notebook.read_text(encoding="utf-8")) pycells = _get_pycells(python_file) for code_cell_number, cell in enumerate( @@ -167,7 +167,9 @@ def mutate(python_file: "Path", notebook: "Path", notebook_info: NotebookInfo) - continue cell["source"] = _get_new_source(code_cell_number, notebook_info, next(pycells)) - notebook.write_text(f"{json.dumps(notebook_json, indent=1, ensure_ascii=False)}\n") + notebook.write_text( + f"{json.dumps(notebook_json, indent=1, ensure_ascii=False)}\n", encoding="utf-8" + ) def _print_diff(code_cell_number: int, cell_diff: Iterator[str]) -> None: @@ -211,7 +213,7 @@ def diff(python_file: "Path", notebook: "Path", notebook_info: NotebookInfo) -> notebook_info Information about notebook cells used for processing """ - notebook_json = json.loads(notebook.read_text()) + notebook_json = json.loads(notebook.read_text(encoding="utf-8")) pycells = _get_pycells(python_file) diff --git a/nbqa/save_source.py b/nbqa/save_source.py index a2cba9e0..e499e431 100644 --- a/nbqa/save_source.py +++ b/nbqa/save_source.py @@ -331,7 +331,7 @@ def main( NotebookInfo """ - cells = json.loads(notebook.read_text())["cells"] + cells = json.loads(notebook.read_text(encoding="utf-8"))["cells"] result = [] cell_mapping = {0: "cell_0:0"} @@ -366,7 +366,9 @@ def main( result.append(re.sub(r";(\s*)$", "\\1", parsed_cell)) line_number += len(parsed_cell.splitlines()) - temp_python_file.write_text("".join(result).rstrip(NEWLINE) + NEWLINE) + temp_python_file.write_text( + "".join(result).rstrip(NEWLINE) + NEWLINE, encoding="utf-8" + ) return NotebookInfo( cell_mapping, trailing_semicolons, temporary_lines, code_cells_to_ignore