Skip to content

Commit

Permalink
Write stubs with utf-8 encoding (#16329)
Browse files Browse the repository at this point in the history
This is to ensure that you don't get encoding errors if docstrings
contains odd characters like emojis.

---------

Co-authored-by: Jørgen Lind <jorgen@3lc.ai>
Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
  • Loading branch information
3 people authored Oct 27, 2023
1 parent 5d40464 commit 4f05dd5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ def generate_stub_for_py_module(
subdir = os.path.dirname(target)
if subdir and not os.path.isdir(subdir):
os.makedirs(subdir)
with open(target, "w") as file:
with open(target, "w", encoding="utf-8") as file:
file.write(output)


Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -3485,7 +3485,7 @@ def f2(): ...
class A:
"""class docstring

a multiline docstring"""
a multiline 😊 docstring"""
def func():
"""func docstring
don't forget to indent"""
Expand All @@ -3512,7 +3512,7 @@ class B:
class A:
"""class docstring

a multiline docstring"""
a multiline 😊 docstring"""
def func() -> None:
"""func docstring
don't forget to indent"""
Expand Down

0 comments on commit 4f05dd5

Please sign in to comment.