Skip to content

Commit 93d5f77

Browse files
authored
Enable PLW1514 rule (use utf-8 encoding) (#3524)
1 parent 9c0a12e commit 93d5f77

File tree

24 files changed

+307
-301
lines changed

24 files changed

+307
-301
lines changed

clai/update_readme.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def test_cli_help(capfd: pytest.CaptureFixture[str]):
2121

2222
this_dir = Path(__file__).parent
2323
readme = this_dir / 'README.md'
24-
content = readme.read_text()
24+
content = readme.read_text(encoding='utf-8')
2525

2626
new_content, count = re.subn('^(## Help\n+```).+?```', rf'\1\n{help_output}\n```', content, flags=re.M | re.S)
2727
assert count, 'help section not found'
2828
if new_content != content:
29-
readme.write_text(new_content)
29+
readme.write_text(new_content, encoding='utf-8')
3030
pytest.fail('`clai --help` output changed.')

docs/.hooks/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def on_post_build(config: Config) -> None:
4343
"""Inject extra CSS into mermaid styles to avoid titles being the same color as the background in dark mode."""
4444
assert bundle_path is not None
4545
if bundle_path.exists():
46-
content = bundle_path.read_text()
46+
content = bundle_path.read_text(encoding='utf-8')
4747
content, _ = re.subn(r'}(\.statediagram)', '}.statediagramTitleText{fill:#888}\1', content, count=1)
48-
bundle_path.write_text(content)
48+
bundle_path.write_text(content, encoding='utf-8')
4949

5050

5151
def replace_uv_python_run(markdown: str) -> str:
@@ -88,7 +88,7 @@ def render_examples(markdown: str) -> str:
8888

8989
def sub_example(m: re.Match[str]) -> str:
9090
example_path = EXAMPLES_DIR / m.group(1)
91-
content = example_path.read_text().strip()
91+
content = example_path.read_text(encoding='utf-8').strip()
9292
# remove leading docstring which duplicates what's in the docs page
9393
content = re.sub(r'^""".*?"""', '', content, count=1, flags=re.S).strip()
9494

docs/.hooks/snippets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def parse_snippet_directive(line: str) -> SnippetDirective | None:
149149

150150
def parse_file_sections(file_path: Path) -> ParsedFile:
151151
"""Parse a file and extract sections marked with ### [section] or /// [section]"""
152-
input_lines = file_path.read_text().splitlines()
152+
input_lines = file_path.read_text(encoding='utf-8').splitlines()
153153
output_lines: list[str] = []
154154
lines_mapping: dict[int, int] = {}
155155

@@ -220,7 +220,7 @@ def format_highlight_lines(highlight_ranges: list[LineRange]) -> str:
220220
return ' '.join(parts)
221221

222222

223-
def inject_snippets(markdown: str, relative_path_root: Path) -> str: # noqa C901
223+
def inject_snippets(markdown: str, relative_path_root: Path) -> str: # noqa: C901
224224
def replace_snippet(match: re.Match[str]) -> str:
225225
line = match.group(0)
226226
directive = parse_snippet_directive(line)

0 commit comments

Comments
 (0)