Description
Are you reporting a bug, or opening a feature request?
This is a bug. It is a regression from the 0.750 version.
Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to simplify your case to a minimal repro.
Here is the code that triggers this bug. It is essentially a list of TypedDict
objects created in some nested fashion. The definitions for these objects are coming from the boto3-stubs
library, which is a typed wrapper around the boto3
library, which is a Python SDK for talking to AWS REST APIs. The same behavior could probably be reproduced with just custom made TypeDict
objects, but, given, the number of them and the relationship between them, it is easier just to reuse the ones from the library.
To install it, you need to have this line in requirements.txt
(the exact version probably does not matter, but this is what I have):
boto3-stubs[autoscaling,cloudwatch,ec2,lambda,logs] == 1.10.35
IMPORTANT: After running pip install
for the above line, one must also run this command to make boto3-stubs
initialize itself:
python -m mypy_boto3
If doing this from tox.ini
, you need to have this line there:
commands_pre = python -m mypy_boto3
Here is the offending code:
import typing as t
from mypy_boto3.ec2.type_defs import (
DescribeInstancesResultTypeDef,
FilterTypeDef,
InstanceNetworkInterfaceAttachmentTypeDef,
InstanceNetworkInterfaceTypeDef,
InstanceStateTypeDef,
InstanceTypeDef,
PlacementTypeDef,
ReservationTypeDef,
TagTypeDef,
)
x: t.List[DescribeInstancesResultTypeDef] = [
DescribeInstancesResultTypeDef(
Reservations=[
ReservationTypeDef(
Instances=[
InstanceTypeDef(
InstanceId="az1-instance1-id1",
Placement=PlacementTypeDef(
AvailabilityZone="az1",
),
State=InstanceStateTypeDef(
Name="running",
),
NetworkInterfaces=[
InstanceNetworkInterfaceTypeDef(
Attachment=InstanceNetworkInterfaceAttachmentTypeDef(
DeviceIndex=0,
),
NetworkInterfaceId="az1-instance1-nic0-id1",
PrivateDnsName="az1-instance1-nic0-dns1",
PrivateIpAddress="az1-instance1-nic0-ip1",
SourceDestCheck=True,
),
],
Tags=[
TagTypeDef(
Key="Name",
Value="az1-instance1",
),
],
),
],
),
],
NextToken="next-token1",
),
DescribeInstancesResultTypeDef(
Reservations=[
ReservationTypeDef(
Instances=[
InstanceTypeDef(
InstanceId="az1-instance2-id2",
Placement=PlacementTypeDef(
AvailabilityZone="az1",
),
State=InstanceStateTypeDef(
Name="running",
),
NetworkInterfaces=[
InstanceNetworkInterfaceTypeDef(
Attachment=InstanceNetworkInterfaceAttachmentTypeDef(
DeviceIndex=0,
),
NetworkInterfaceId="az1-instance2-nic0-id2",
PrivateDnsName="az1-instance2-nic0-dns2",
PrivateIpAddress="az1-instance2-nic0-ip2",
SourceDestCheck=True,
),
],
Tags=[
TagTypeDef(
Key="Name",
Value="az1-instance2",
),
],
),
],
),
],
NextToken="next-token2",
),
DescribeInstancesResultTypeDef(
Reservations=[
ReservationTypeDef(
Instances=[
InstanceTypeDef(
InstanceId="az2-instance1-id1",
Placement=PlacementTypeDef(
AvailabilityZone="az2",
),
State=InstanceStateTypeDef(
Name="running",
),
NetworkInterfaces=[
InstanceNetworkInterfaceTypeDef(
Attachment=InstanceNetworkInterfaceAttachmentTypeDef(
DeviceIndex=0,
),
NetworkInterfaceId="az2-instance1-nic0-id1",
PrivateDnsName="az2-instance1-nic0-dns1",
PrivateIpAddress="az2-instance1-nic0-ip1",
SourceDestCheck=True,
),
],
Tags=[
TagTypeDef(
Key="Name",
Value="az2-instance1",
),
],
),
],
),
],
),
]
What is the actual behavior/output?
When running mypy
for this file, version 0.750 takes about 8-10 seconds to complete without any errors (with a brand new completely empty .mypy_cache
). All versions after that (for the list of versions I tried, see below) essentially hang and never complete. When I was doing this on the actual project code, I had mypy
running for at least half an hour. When running experiments specifically with the above code, I waited for a couple of minutes for each version before killing it in the Task Manager.
What is the behavior/output you expect?
mypy
should not hang on this file.
What are the versions of mypy and Python you are using?
> python --version --version
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)]
mypy
versions tried:
- 0.750 - works
- 0.761 - hangs
- 0.770 - hangs
- 0.780 - hangs
- 0.782 - hangs
Do you see the same issue after installing mypy from Git master?
I only tried the officially published versions listed above.
What are the mypy flags you are using? (For example --strict-optional)
Here is the content of mypy.ini
that I used:
[mypy]
mypy_path = ./stubs
# How imports are handled
ignore_missing_imports = False
follow_imports = normal
# Enforce various type annotations
disallow_any_unimported = True
disallow_any_expr = False
disallow_any_decorated = False
disallow_any_explicit = False
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
# Various code quality checks
no_implicit_optional = True
strict_optional = True
warn_unused_ignores = True
warn_no_return = True
warn_return_any = True
warn_unreachable = True
warn_redundant_casts = True
allow_untyped_globals = False
allow_redefinition = False
strict_equality = True
# How error messages are printed
show_error_context = False
show_column_numbers = True
show_error_codes = True
pretty = True
If mypy crashed with a traceback, please paste the full traceback below.
mypy
does not crash, just hangs. It needs to be killed in the Task Manager to stop it. It does not even respond to Ctrl
+C
.