python / mypy

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

dmypy crashes when switching branches #16754

Open Randl opened 11 months ago

Randl commented 11 months ago

Crash Report

I'm running mypy on qiskit. If I run the daemon and then switch branches, mypy crashes. The branches are https://github.com/Qiskit/qiskit/commit/fbb0938686a8e00ca00625799edde8803c32fb56 and https://github.com/Randl/qiskit-terra/commit/7046f116a645c390ef8c7e5f2f39c17f07bd8295 The command is

 dmypy run -- --ignore-missing-imports --no-strict-optional --allow-untyped-globals --allow-redefinition --show-error-codes  --check-untyped-defs --show-traceback  qiskit

Traceback

version: 1.9.0+dev.fbb738a4626976f83a7412df73533d87483a31b7
Daemon crashed!
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/dmypy_server.py", line 236, in serve
    resp = self.run_command(command, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/dmypy_server.py", line 285, in run_command
    ret = method(self, **data)
          ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/dmypy_server.py", line 353, in cmd_run
    return self.check(sources, export_types, is_tty, terminal_width)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/dmypy_server.py", line 429, in check
    messages = self.fine_grained_increment_follow_imports(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/dmypy_server.py", line 631, in fine_grained_increment_follow_imports
    messages = fine_grained_manager.update(changed, [], followed=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/server/update.py", line 267, in update
    result = self.update_one(
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/server/update.py", line 369, in update_one
    result = self.update_module(next_id, next_path, next_id in removed_set, followed)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/server/update.py", line 452, in update_module
    remaining += propagate_changes_using_dependencies(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/server/update.py", line 881, in propagate_changes_using_dependencies
    triggered |= reprocess_nodes(manager, graph, id, nodes, deps, processed_targets)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/server/update.py", line 1010, in reprocess_nodes
    semantic_analysis_for_targets(graph[module_id], nodes, graph, saved_attrs)
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal_main.py", line 137, in semantic_analysis_for_targets
    process_top_levels(graph, [state.id], patches)
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal_main.py", line 220, in process_top_levels
    deferred, incomplete, progress = semantic_analyze_target(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal_main.py", line 349, in semantic_analyze_target
    analyzer.refresh_partial(
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 597, in refresh_partial
    self.refresh_top_level(node)
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 608, in refresh_top_level
    self.accept(d)
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 6544, in accept
    report_internal_error(err, self.errors.file, node.line, self.errors, self.options)
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/errors.py", line 1261, in report_internal_error
    raise err
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 6542, in accept
    node.accept(self)
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/nodes.py", line 1310, in accept
    return visitor.visit_assignment_stmt(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 2860, in visit_assignment_stmt
    if self.check_and_set_up_type_alias(s):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 3617, in check_and_set_up_type_alias
    res, alias_tvars, depends_on, qualified_tvars, empty_tuple_index = self.analyze_alias(
                                                                       ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 3506, in analyze_alias
    analyzed, depends_on = analyze_type_alias(
                           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 156, in analyze_type_alias
    res = type.accept(analyzer)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/types.py", line 955, in accept
    return visitor.visit_unbound_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 259, in visit_unbound_type
    typ = self.visit_unbound_type_nonoptional(t, defining_literal)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 399, in visit_unbound_type_nonoptional
    special = self.try_analyze_special_unbound_type(t, fullname)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 624, in try_analyze_special_unbound_type
    return self.analyze_literal_type(t)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 1470, in analyze_literal_type
    analyzed_types = self.analyze_literal_param(i + 1, arg, t)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 1536, in analyze_literal_param
    fallback = self.named_type(arg.base_type_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 1735, in named_type
    node = self.lookup_fully_qualified(fully_qualified_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/typeanal.py", line 256, in lookup_fully_qualified
    return self.api.lookup_fully_qualified(name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mypy/semanal.py", line 5855, in lookup_fully_qualified
    assert ret is not None, fullname
           ^^^^^^^^^^^^^^^
AssertionError: builtins.int

To Reproduce

Checkout one branch, run dmypy, checkout second branch, run dmypy.

Your Environment

Randl commented 11 months ago

Probably related to https://github.com/python/mypy/issues/16744 and https://github.com/python/mypy/issues/14645