Skip to content

Commit 864b728

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "IMPR: replace codecs.open() with pathlib methods in pagefromfile.py"
2 parents a12d1a0 + de713d9 commit 864b728

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

scripts/pagefromfile.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@
7171
between them by specifying '\n' as a value.
7272
"""
7373
#
74-
# (C) Pywikibot team, 2004-2024
74+
# (C) Pywikibot team, 2004-2025
7575
#
7676
# Distributed under the terms of the MIT license.
7777
#
7878
from __future__ import annotations
7979

80-
import codecs
8180
import os
8281
import re
82+
from pathlib import Path
8383

8484
import pywikibot
8585
from pywikibot import config, i18n
@@ -231,11 +231,9 @@ def generator(self) -> Generator[pywikibot.Page, None, None]:
231231
changed from iterator method to generator property
232232
"""
233233
pywikibot.info(f"\n\nReading '{self.filename}'...")
234+
filepath = Path(self.filename)
234235
try:
235-
with codecs.open(self.filename, 'r',
236-
encoding=config.textfile_encoding) as f:
237-
text = f.read()
238-
236+
text = filepath.read_text(encoding=config.textfile_encoding)
239237
except OSError as e:
240238
pywikibot.error(e)
241239
return

0 commit comments

Comments
 (0)