Repository navigation
Mypy 1.11.0 crashes on typing.NotRequired with --html-report #17604
Copy link
Copy link
Closed
Labels
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
Reactions are currently unavailable
Activity
nernst commentedon Jul 30, 2024
I've hit a very similar crash in 1.11 involving Required/NotRequired in a TypedDict as well. In my case, html report is not required:
I have the type ignore because I don't have stubs for bson. If I remove the import of ObjectId and change the type on
_idto bestr, the code analyses fine. Traceback looks a little more interesting in my case:JelleZijlstra commentedon Jul 30, 2024
@nernst could you report a separate bug and leave this one limited to the html-report issue?
[-]Mypy 1.11.0 crashes on typing.NotRequired[/-][+]Mypy 1.11.0 crashes on typing.NotRequired with `--html-report`[/+]andersk commentedon Jul 30, 2024
git bisectsays this was introduced by e5b3b56 (Fix daemon crash on invalid type in TypedDict, #17495).Note that to reproduce without mypyc, you need to manually insert this assertion that would be enforced automatically by mypyc:
(So far this seems similar to @nernst’s #17608.)
Fix crash on unimported Any with Required/NotRequired
Fix crash on unimported Any with Required/NotRequired
Unwrap TypedDict item types before storing (python#17640)
Unwrap TypedDict item types before storing (python#17640)
Unwrap TypedDict item types before storing (#17640)