-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Crash Report
--pretty inserts source file fragments from the file that's being reported. If --shadow-file uses a SHADOW_FILE which is longer than SOURCE_FILE, mypy crashes as it tries to access a line which doesn't exist.
To Reproduce & Traceback
a.py
b: bytes # Ensure there is at most 1 newline character in this fileb.py
a: int = ""
b: bytes = 1$ mypy a.py --pretty --shadow-file a.py b.py
Traceback (most recent call last):
...
File "<virtual environment>\lib\site-packages\mypy\__main__.py", line 15, in console_entry
main()
File "mypy\main.py", line 103, in main
File "mypy\main.py", line 187, in run_build
File "mypy\build.py", line 193, in build
File "mypy\build.py", line 268, in _build
File "mypy\build.py", line 2950, in dispatch
File "mypy\build.py", line 3348, in process_graph
File "mypy\build.py", line 3471, in process_stale_scc
File "mypy\errors.py", line 923, in file_messages
File "mypy\errors.py", line 883, in format_messages
IndexError: list index out of rangeLine 883 in 1a2c8e2
| source_line = source_lines[line - 1] |
I think the solution is to insert source file fragments from SHADOW_FILE rather than SOURCE_FILE. Even if this doesn't crash, the resultant messages don't make sense. For example, inserting extra newlines into a.py prevents the crash but you get
a.py:1:10:1:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
b: bytes
^
a.py:2:12:2:12: error: Incompatible types in assignment (expression has type "int", variable has type "bytes") [assignment]
^Your Environment
- Mypy version used: 1.11.2
- Mypy command-line flags:
--pretty --shadow-file - Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.9
- Operating system and version: Windows 11 Home