-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mypy 1.11.0 crashes on typing.NotRequired with --html-report
#17604
Comments
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: from typing import NotRequired, Required, TypedDict
from bson.objectid import ObjectId # type: ignore
class Data(TypedDict, total=False):
_id: Required[ObjectId] # or NotRequired, either crashes
appId: str 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
|
@nernst could you report a separate bug and leave this one limited to the html-report issue? |
--html-report
Note that to reproduce without mypyc, you need to manually insert this assertion that would be enforced automatically by mypyc: --- a/mypy/types.py
+++ b/mypy/types.py
@@ -3108,7 +3108,8 @@ def get_proper_type(typ: Type | None) -> ProperType | None:
while isinstance(typ, TypeAliasType):
typ = typ._expand_once()
# TODO: store the name of original type alias on this type, so we can show it in errors.
- return cast(ProperType, typ)
+ assert isinstance(typ, ProperType)
+ return typ
@overload |
Fixes python#17604; fixes python#17608. (To reproduce the crash without mypyc, replace `cast(ProperType, typ)` with an assertion in `get_proper_type`.) Signed-off-by: Anders Kaseorg <[email protected]>
Fixes python#17604; fixes python#17608. (To reproduce the crash without mypyc, replace `cast(ProperType, typ)` with an assertion in `get_proper_type`.) Signed-off-by: Anders Kaseorg <[email protected]>
Fixes python#17604 Fixes python#17608 Fix is trivial, rectify an obvious omission in my original PR. (cherry picked from commit b56f357)
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 onTypedDict
:Running mypy on it with
--html-report
causes a crash:When I change the
NotRequired[str]
to plainstr
, 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
--html-report mypy --show-traceback reproduce.py
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: