Skip to content

Make Python HasIterparse compatible with mypy 2.4 - #863

Merged
mristin merged 1 commit into
mainfrom
mristin/Fix-HasIterparse-for-newer-typeshed
Oct 23, 2026
Merged

mristin merged 1 commit into
mainfrom
mristin/Fix-HasIterparse-for-newer-typeshed

Conversation

@mristin

@mristin mristin commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

We bump mypy in the Python live tests from 0.982 to 2.4.0, the version the generated SDKs use. Its type stubs declare iterparse of xml.etree.ElementTree as overloads over literal event names, so the module no longer satisfies our HasIterparse protocol, and every default has_iterparse = xml.etree.ElementTree fails to type-check.

The protocol now requires only the events we actually pass, without a default, so that a single overload matches it:

def iterparse(
    self, source: TextIO, events: Sequence[Literal["start", "end"]]
) -> Iterator[Tuple[str, Element]]:

This fix is necessary for mypy 2.4.0; the old stubs accept it as well.

We bump mypy in the Python live tests from 0.982 to 2.4.0, the version
the generated SDKs use. Its type stubs declare ``iterparse`` of
``xml.etree.ElementTree`` as overloads over literal event names, so
the module no longer satisfies our ``HasIterparse`` protocol, and every
default ``has_iterparse = xml.etree.ElementTree`` fails to type-check.

The protocol now requires only the events we actually pass, without
a default, so that a single overload matches it:

    def iterparse(
        self, source: TextIO, events: Sequence[Literal["start", "end"]]
    ) -> Iterator[Tuple[str, Element]]:

This fix is necessary for mypy 2.4.0; the old stubs accept it as well.
@mristin
mristin merged commit bc28d91 into main Oct 23, 2026
5 checks passed
@mristin
mristin deleted the mristin/Fix-HasIterparse-for-newer-typeshed branch October 23, 2026 15:02
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 39972867254

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 90.201%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 51365
Covered Lines: 46332
Line Coverage: 90.2%
Coverage Strength: 2.71 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants