-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
mypy appears to become inefficient for nested ifs (see example)
To Reproduce
Consider the following (bad) code example:
cat << EOF > lint_me.py
special_overrides = True
print(sorted(["c", "b", "a"], key=lambda kv: kv[0] if not special_overrides else \\
'a' if kv[0] == 'a_01' else \\
'b' if kv[0] == 'b_02' else \\
'c' if kv[0] == 'c_03' else \\
'd' if kv[0] == 'd_04' else \\
'e' if kv[0] == 'e_05' else \\
'f' if kv[0] == 'f_06' else \\
'g' if kv[0] == 'g_07' else \\
'h' if kv[0] == 'h_08' else \\
'i' if kv[0] == 'i_09' else \\
'j' if kv[0] == 'j_10' else \\
'k' if kv[0] == 'k_11' else \\
'l' if kv[0] == 'l_12' else \\
'm' if kv[0] == 'm_13' else \\
'n' if kv[0] == 'n_14' else \\
'o' if kv[0] == 'o_15' else \\
'p' if kv[0] == 'p_16' else \\
'q' if kv[0] == 'q_17' else \\
kv[0]))
EOF
Expected Behavior
mypy can complain about very bad code in a reasonable time
Actual Behavior
with each additional if the total runtime seems to double:
13 nested ifs (until m): real 0m33.827s
14 nested ifs (until n): real 1m10.013s
15 nested ifs (until o): real 2m3.904s
16 nested ifs (until p): real 4m3.223s
17 nested ifs (until q): real 8m27.333s
Your Environment
- Mypy version used:
0.790 - Mypy command-line flags: None (just
python -m mypy lint_me.py) - Mypy configuration options from
mypy.ini(and other config files): None - Python version used:
Python 3.8.1 - Operating system and version:
Windows 10, Version 10.0.19041 Build 19041