Closed
Description
Crash Report
Mypy crashes on a Python file that makes use of typing.NotRequired
when used with the --html-report
option.
Traceback
To Reproduce
I took an example from the typing
docs on TypedDict
:
from typing import NotRequired, TypedDict
class Point2D(TypedDict):
x: int
y: int
label: NotRequired[str]
Running mypy on it with --html-report
causes a crash:
(sandbox-312) sander@bedevere:~/documents/projects/python-sandbox$ mypy --html-report mypy --show-traceback reproduce.py
reproduce.py: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.11.0
Traceback (most recent call last):
File "/home/sander/.virtualenvs/sandbox-312/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "mypy/build.py", line 2069, in wrap_context
TypeError: mypy.types.ProperType object expected; got mypy.types.RequiredType
reproduce.py: : note: use --pdb to drop into pdb
Generated HTML report (via XSLT): /home/sander/documents/projects/python-sandbox/mypy/index.html
(sandbox-312) sander@bedevere:~/documents/projects/python-sandbox$ cat mypy/index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="mypy-html.css">
</head>
<body>
<h1>Mypy Type Check Coverage Summary</h1>
<table class="summary">
<caption>Summary from index</caption>
<thead><tr class="summary">
<th class="summary">File</th>
<th class="summary">Imprecision</th>
<th class="summary">Lines</th>
</tr></thead>
<tfoot><tr class="summary summary-quality-0">
<th class="summary summary-filename">Total</th>
<th class="summary summary-precision">0.00% imprecise</th>
<th class="summary summary-lines">0 LOC</th>
</tr></tfoot>
<tbody></tbody>
</table>
</body>
</html>
(sandbox-312) sander@bedevere:~/documents/projects/python-sandbox$ mypy --version
mypy 1.11.0 (compiled: yes)
When I change the NotRequired[str]
to plain str
, mypy succeeds. The issue also doesn't occur without the --html-report
option.
I failed to reproduce the issue from a source installation, even from a checked out v1.11.0
tag. But I get it consistently with the 1.11.0 version published to PyPi.
Your Environment
- Mypy version used: 1.11.0 (from PyPi, could not reproduce from source installation, even from checked out v1.11.0 tag)
- Mypy command-line flags:
--html-report mypy --show-traceback reproduce.py
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.11 and 3.12
- Operating system and version: Arch Linux