Skip to content

Commit

Permalink
fix: always specify encoding (#135)
Browse files Browse the repository at this point in the history
### Summary of Changes

Always specify the encoding when opening files.
  • Loading branch information
lars-reimann authored May 15, 2024
1 parent aec4abd commit d894a8a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 30 deletions.
21 changes: 0 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ mkdocs-material = "^9.4.7"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
addopts = "--ignore=./tests/data"

[tool.black]
line-length = 120

[tool.pytest.ini_options]
addopts = "--ignore=./tests/data --tb=short"
6 changes: 3 additions & 3 deletions src/safeds_stubgen/stubs_generator/_generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def create_stub_files(
file_path = Path(corrected_module_dir / f"{public_module_name}.sdsstub")
Path(file_path).touch()

with file_path.open("w") as f:
with file_path.open("w", encoding="utf-8") as f:
f.write(module_text)

created_module_paths: set[str] = set()
Expand Down Expand Up @@ -138,10 +138,10 @@ def _create_outside_package_class(

file_path = Path(module_dir / f"{module_name}.sdsstub")
if Path.exists(file_path) and not first_creation:
with file_path.open("a") as f:
with file_path.open("a", encoding="utf-8") as f:
f.write(_create_outside_package_class_text(class_name, naming_convention))
else:
with file_path.open("w") as f:
with file_path.open("w", encoding="utf-8") as f:
module_text = ""

# package name & annotation
Expand Down
2 changes: 1 addition & 1 deletion tests/data/various_modules_package/infer_types_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"):
else:
infer_param_2 = 0

with open("no path", "r") as _:
with open("no path", "r", encoding="utf-8") as _:
if infer_param_2:
return "Some String"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_file_creation_limited_stubs_outside_package(snapshot_sds_stub: Snapshot
path = Path(_out_dir / "tests/data/main_package/another_path/another_module/another_module.sdsstub")
assert path.is_file()

with path.open("r") as f:
with path.open("r", encoding="utf-8") as f:
assert f.read() == snapshot_sds_stub


Expand Down
2 changes: 1 addition & 1 deletion tests/safeds_stubgen/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_main(snapshot: SnapshotAssertion) -> None:

main()

with Path.open(_out_file_dir) as f:
with Path.open(_out_file_dir, encoding="utf-8") as f:
json_data = json.load(f)

assert json_data == snapshot
Expand Down

0 comments on commit d894a8a

Please sign in to comment.