python / python/mypy

Invalid JUnit XML being generated due to <type> hint

Open
#16,915 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-error-reporting
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report
The JUnit XML generated by MyPy is invalid.

To Reproduce
Create a list without a type annotation and generate a JUnit XML report using MyPy.

def dummy_function():
    abc = []
    for i in ["asd", 123]:
        abc.append(i)

Expected Behavior
I expect a valid XML document to be generated.

Actual Behavior
The XML is unable to be parsed due to a mismatched tag. I believe this is because of the presence of a <type> mask in a hint.
error: Need type annotation for "abc" (hint: "abc: List[<type>] = ...")

This is the XML error message that is displayed

XML Parsing Error: mismatched tag. Expected: </type>
Location: [file_path]
Line Number XXX, Column XXX:

[Error location]:8: error: Function is missing a type annotation [no-untyped-def]</failure>

Your Environment
Mac with Sonoma 14.3 and using the Poetry package manager

  • Mypy version used: 1.8.0
  • Mypy command-line flags: --explicit-package-bases --strict --junit-xml ./mypy-report.xml
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.10

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

Reproduce the report with the provided Python example and the --junit-xml ./mypy-report.xml command, then inspect the JUnit XML generation path. Done means the generated report is valid XML when diagnostics contain the <type> hint, including the reported no-untyped-def case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.