From 9d05c7c60d06b0f7d9a1c17c5e0509bf5cf09f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Thu, 26 Oct 2023 10:31:48 +0200 Subject: [PATCH 1/2] Write stubs with utf-8 encoding This is to ensure that you don't get encoding errors if docstrings contains odd characters like emojis. --- mypy/stubgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/stubgen.py b/mypy/stubgen.py index a2f07a35eaa2..837cd723c410 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -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) From b1083f1358c4828aa2adb75dd5e0418860dd2d08 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 27 Oct 2023 12:19:11 -0700 Subject: [PATCH 2/2] add test --- test-data/unit/stubgen.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index 64a1353b29b3..895500c1ba57 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -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""" @@ -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"""