python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.57k stars 2.85k forks source link

dmypy: INTERNAL ERROR: AssertionError in _add_error_info() #15486

Open asqui opened 1 year ago

asqui commented 1 year ago

Crash Report

Just trying out dmypy for the first time and I encountered the below issue when trying to check an individual file after starting the daemon and checking the entire source repository.

Repro / Traceback

$ time dmypy run -- src/ ; time dmypy run -- src/scratch.py ; time dmypy run -- src/scratch.py
Daemon started
src/scratch.py:16: error: "C" has no attribute "foo"  [attr-defined]
Found 1 error in 1 file (checked 2952 source files)

real    2m1.636s
user    0m0.264s
sys     0m0.140s
src/scratch.py:16: error: "C" has no attribute "foo"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

real    0m54.281s
user    0m0.174s
sys     0m0.098s
-------------------------------------------------------------------------------
stderr:
src/scratch.py:16: 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.3.0
src/scratch.py:16: 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.3.0
Daemon crashed!
Traceback (most recent call last):
  File "mypy/dmypy_server.py", line 230, in serve
  File "mypy/dmypy_server.py", line 277, in run_command
  File "mypy/dmypy_server.py", line 345, in cmd_run
  File "mypy/dmypy_server.py", line 414, in check
  File "mypy/dmypy_server.py", line 663, in fine_grained_increment_follow_imports
  File "mypy/server/update.py", line 288, in update
  File "mypy/server/update.py", line 881, in propagate_changes_using_dependencies
  File "mypy/server/update.py", line 1024, in reprocess_nodes
  File "mypy/checker.py", line 526, in check_second_pass
  File "mypy/checker.py", line 531, in check_partial
  File "mypy/checker.py", line 545, in check_top_level
  File "mypy/nodes.py", line 1228, in accept
  File "mypy/checker.py", line 4130, in visit_expression_stmt
  File "mypy/checkexpr.py", line 4892, in accept
  File "mypy/errors.py", line 1177, in report_internal_error
  File "mypy/checkexpr.py", line 4882, in accept
  File "mypy/checkexpr.py", line 429, in visit_call_expr
  File "mypy/checkexpr.py", line 515, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 4892, in accept
  File "mypy/errors.py", line 1177, in report_internal_error
  File "mypy/checkexpr.py", line 4890, in accept
  File "mypy/nodes.py", line 1813, in accept
  File "mypy/checkexpr.py", line 2771, in visit_member_expr
  File "mypy/checkexpr.py", line 2792, in analyze_ordinary_member_access
  File "mypy/checkmember.py", line 201, in analyze_member_access
  File "mypy/checkmember.py", line 220, in _analyze_member_access
  File "mypy/checkmember.py", line 343, in analyze_instance_member_access
  File "mypy/checkmember.py", line 601, in analyze_member_var_access
  File "mypy/checkmember.py", line 274, in report_missing_attribute
  File "mypy/messages.py", line 485, in has_no_attr
  File "mypy/messages.py", line 272, in fail
  File "mypy/messages.py", line 247, in report
  File "mypy/errors.py", line 440, in report
  File "mypy/errors.py", line 502, in add_error_info
  File "mypy/errors.py", line 443, in _add_error_info
AssertionError

real    0m0.863s
user    0m0.158s
sys     0m0.107s

Observations

  1. Checking our entire source repo of 2,952 files takes ~2 minutes, and then re-checking a single file (which has not been modified, was already checked, and had its errors reported in the first run) takes nearly a minute. This seems very surprising. (I'd expect this to be near instant, given the file has not been modified since the initial check?)
  2. This crash only seems to happen if scratch.py has an error it it. If I 'fix' the error in that file, the crash does not occur, though the curiosity of re-checking the individual file taking nearly a minute remains.

Environment

ikonst commented 1 year ago

Did you mean to also provide the contents of src/scratch.py here?

asqui commented 1 year ago

src/scratch.py looks something like this:

from foo import bar  # Import from our internal codebase

class A:
    pass

A().foo()

(Unfortunately I can't share the codebase that this is interacting with.)