Skip to content

Modernize annotation usage in libregrtest #156402

Description

@ashm-dev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtopic-typingtype-refactorCode refactoring (with no changes in behavior)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions