python / python/cpython

Modernize annotation usage in libregrtest

Open
#156,402 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

tests topic-typing type-refactor
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug description:

Lib/test/libregrtest/results.py imports TYPE_CHECKING only to guard a type-only import:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from xml.etree.ElementTree import Element

Now that explicit lazy imports are available, this can be replaced with:

lazy from xml.etree.ElementTree import Element

The stringized list['Element'] annotation can then become list[Element]. This keeps xml.etree.ElementTree from being imported eagerly while making the annotation name available at runtime.

Lib/test/libregrtest/mypy.ini should also target Python 3.15, following the approach used for pyrepl in gh-149985 and gh-149992.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-156403

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Lib/test/libregrtest/results.py and Lib/test/libregrtest/mypy.ini; inspect the existing annotation and type-checking configuration, then compare the pyrepl approach in gh-149985 and gh-149992. Done means the lazy annotation import and runtime annotation are used without eager XML imports, and mypy targets Python 3.15.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.