Skip to content

Commit a73656a

Browse files
committed
Modernize annotation usage in libregrtest
1 parent e2118b0 commit a73656a

6 files changed

Lines changed: 11 additions & 19 deletions

File tree

Lib/test/libregrtest/main.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,7 @@ def finalize_tests(self, coverage: trace.CoverageResults | None) -> None:
470470
os.unlink(self.next_single_filename)
471471

472472
if coverage is not None:
473-
# uses a new-in-Python 3.13 keyword argument that mypy doesn't know about yet:
474-
coverage.write_results(show_missing=True, summary=True, # type: ignore[call-arg]
473+
coverage.write_results(show_missing=True, summary=True,
475474
coverdir=self.coverage_dir,
476475
ignore_missing_files=True)
477476

@@ -539,10 +538,7 @@ def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
539538
if self.num_workers < 0:
540539
# Use all CPUs + 2 extra worker processes for tests
541540
# that like to sleep
542-
#
543-
# os.process.cpu_count() is new in Python 3.13;
544-
# mypy doesn't know about it yet
545-
self.num_workers = (os.process_cpu_count() or 1) + 2 # type: ignore[attr-defined]
541+
self.num_workers = (os.process_cpu_count() or 1) + 2
546542

547543
# For a partial run, we do not need to clutter the output.
548544
if (self.want_header

Lib/test/libregrtest/mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[mypy]
66
files = Lib/test/libregrtest
77
explicit_package_bases = True
8-
python_version = 3.12
8+
python_version = 3.15
99
platform = linux
1010
pretty = True
1111

Lib/test/libregrtest/refleak.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ def runtest_refleak(test_name, test_func,
9595

9696
# `ByteString` is not included in `collections.abc.__all__`
9797
with warnings.catch_warnings(action='ignore', category=DeprecationWarning):
98-
ByteString = collections.abc.ByteString
99-
# Mypy doesn't even think `ByteString` is a class, hence the `type: ignore`
100-
for obj in ByteString.__subclasses__() + [ByteString]: # type: ignore[attr-defined]
98+
ByteString = collections.abc.ByteString # type: ignore[attr-defined]
99+
for obj in ByteString.__subclasses__() + [ByteString]:
101100
abcs[obj] = _get_dump(obj)[0]
102101

103102
# bpo-31217: Integer pool to get a single integer object for the same
@@ -154,9 +153,7 @@ def get_pooled_int(value):
154153
# Also, readjust the reference counts and alloc blocks by ignoring
155154
# any strings that might have been interned during test_func. These
156155
# strings will be deallocated at runtime shutdown
157-
interned_immortal_after = getunicodeinternedsize(
158-
# Use an internal-only keyword argument that mypy doesn't know yet
159-
_only_immortal=True) # type: ignore[call-arg]
156+
interned_immortal_after = getunicodeinternedsize(_only_immortal=True)
160157
alloc_after = getallocatedblocks() - interned_immortal_after
161158
rc_after = gettotalrefcount()
162159
fd_after = fd_count()

Lib/test/libregrtest/results.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import sys
22
import trace
33
from _colorize import get_colors # type: ignore[import-not-found]
4-
from typing import TYPE_CHECKING
54

65
from .runtests import RunTests
76
from .result import State, TestResult, TestStats, Location
87
from .utils import (
98
StrPath, TestName, TestTuple, TestList, FilterDict,
109
printlist, count, format_duration)
1110

12-
if TYPE_CHECKING:
13-
from xml.etree.ElementTree import Element
11+
lazy from xml.etree.ElementTree import Element
1412

1513

1614
# Python uses exit code 1 when an exception is not caught
@@ -41,7 +39,7 @@ def __init__(self) -> None:
4139
self.test_times: list[tuple[float, TestName]] = []
4240
self.stats = TestStats()
4341
# used by --junit-xml
44-
self.testsuite_xml: list['Element'] = []
42+
self.testsuite_xml: list[Element] = []
4543
# used by -T with -j
4644
self.covered_lines: set[Location] = set()
4745

Lib/test/libregrtest/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,7 @@ def display_header(use_resources: dict[str, str | None],
657657

658658
cpu_count: object = os.cpu_count()
659659
if cpu_count:
660-
# The function is new in Python 3.13; mypy doesn't know about it yet:
661-
process_cpu_count = os.process_cpu_count() # type: ignore[attr-defined]
660+
process_cpu_count = os.process_cpu_count()
662661
if process_cpu_count and process_cpu_count != cpu_count:
663662
cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)"
664663
print("== CPU count:", cpu_count)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Modernize annotation usage in :mod:`!test.libregrtest` by replacing a
2+
type-checking-only import with a lazy import. Patched by Shamil Abdulaev.

0 commit comments

Comments
 (0)