Skip to content

Commit

Permalink
Use the content encoding to decode the header
Browse files Browse the repository at this point in the history
When decoding the header to put it back at the top of the contents of
the file, use the same encoding used in the content. This should be a
better "guess" that using the default value

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
  • Loading branch information
aaossa committed Oct 6, 2022
1 parent 6177cb3 commit 62dd941
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,8 @@ def format_file_in_place(
raise ValueError(
f"File '{src}' cannot be parsed as valid Jupyter notebook."
) from None
src_contents = header.decode() + src_contents
dst_contents = header.decode() + dst_contents
src_contents = header.decode(encoding) + src_contents
dst_contents = header.decode(encoding) + dst_contents

if write_back == WriteBack.YES:
with open(src, "w", encoding=encoding, newline=newline) as f:
Expand Down

0 comments on commit 62dd941

Please sign in to comment.