Skip to content

Commit c39a329

Browse files
authored
gh-156402: Modernize annotation usage in libregrtest (#156403)
1 parent b215552 commit c39a329

5 files changed

Lines changed: 9 additions & 20 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
@@ -96,9 +96,8 @@ def runtest_refleak(test_name, test_func,
9696

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

104103
warmups = hunt_refleak.warmups
@@ -151,9 +150,7 @@ def runtest_refleak(test_name, test_func,
151150
# Also, readjust the reference counts and alloc blocks by ignoring
152151
# any strings that might have been interned during test_func. These
153152
# strings will be deallocated at runtime shutdown
154-
interned_immortal_after = getunicodeinternedsize(
155-
# Use an internal-only keyword argument that mypy doesn't know yet
156-
_only_immortal=True) # type: ignore[call-arg]
153+
interned_immortal_after = getunicodeinternedsize(_only_immortal=True)
157154
alloc_after = getallocatedblocks() - interned_immortal_after
158155
rc_after = gettotalrefcount()
159156
fd_after = fd_count()

Lib/test/libregrtest/results.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +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
4+
lazy from xml.etree.ElementTree import Element
55

66
from .runtests import RunTests
77
from .result import State, TestResult, TestStats, Location
88
from .utils import (
99
StrPath, TestName, TestTuple, TestList, FilterDict,
1010
printlist, count, format_duration)
1111

12-
if TYPE_CHECKING:
13-
from xml.etree.ElementTree import Element
14-
1512

1613
# Python uses exit code 1 when an exception is not caught
1714
# argparse.ArgumentParser.error() uses exit code 2
@@ -41,7 +38,7 @@ def __init__(self) -> None:
4138
self.test_times: list[tuple[float, TestName]] = []
4239
self.stats = TestStats()
4340
# used by --junit-xml
44-
self.testsuite_xml: list['Element'] = []
41+
self.testsuite_xml: list[Element] = []
4542
# used by -T with -j
4643
self.covered_lines: set[Location] = set()
4744

Lib/test/libregrtest/utils.py

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

653653
cpu_count: object = os.cpu_count()
654654
if cpu_count:
655-
# The function is new in Python 3.13; mypy doesn't know about it yet:
656-
process_cpu_count = os.process_cpu_count() # type: ignore[attr-defined]
655+
process_cpu_count = os.process_cpu_count()
657656
if process_cpu_count and process_cpu_count != cpu_count:
658657
cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)"
659658
print("== CPU count:", cpu_count)

0 commit comments

Comments
 (0)