python / python/mypy

del partial_types[var] fails with KeyError: <Var 'errors' at 0x...>

Open
#20,792 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

crash
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Crash Report

Followed the instructions after getting the internal error:

src/foo/foo.py:17: 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.20.0+dev.92a78583b1cd0c9d0cc3966dfc534020128888ca

Traceback

Traceback (most recent call last):
  File "/path/to/.venv/bin/mypy", line 10, in <module>
    sys.exit(console_entry())
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/main.py", line 135, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/main.py", line 219, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/build.py", line 371, in build
    result = build_inner(
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/build.py", line 468, in build_inner
    graph = dispatch(sources, manager, stdout)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/build.py", line 3582, in dispatch
    process_graph(graph, manager)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/build.py", line 4047, in process_graph
    done, still_working, results = manager.wait_for_done(graph)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/build.py", line 1189, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/build.py", line 4215, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/build.py", line 2904, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 537, in check_first_pass
    self.accept(d)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 648, in accept
    stmt.accept(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/nodes.py", line 1004, in accept
    return visitor.visit_func_def(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 1197, in visit_func_def
    self.check_func_item(defn, name=defn.name)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 1233, in check_func_item
    self.check_func_def(defn, typ, name, allow_empty)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 1437, in check_func_def
    self.accept(item.body)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 648, in accept
    stmt.accept(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/nodes.py", line 1582, in accept
    return visitor.visit_block(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 3164, in visit_block
    self.accept(s)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 648, in accept
    stmt.accept(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/nodes.py", line 1912, in accept
    return visitor.visit_try_stmt(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 5216, in visit_try_stmt
    self.visit_try_without_finally(s, try_frame=bool(s.finally_body))
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 5285, in visit_try_without_finally
    self.accept(s.else_body)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 648, in accept
    stmt.accept(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/nodes.py", line 1582, in accept
    return visitor.visit_block(self)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 3164, in visit_block
    self.accept(s)
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 648, in accept
    stmt.accept(self)
    ~~~~~~~~~~~^^^^^^
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/nodes.py", line 1669, in accept
    return visitor.visit_assignment_stmt(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 3215, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 3275, in check_assignment
    self.try_infer_partial_generic_type_from_assignment(lvalue, rvalue, "=")
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.14/site-packages/mypy/checker.py", line 3547, in try_infer_partial_generic_type_from_assignment
    del partial_types[var]
        ~~~~~~~~~~~~~^^^^^
KeyError: <Var 'errors' at 0x105f66200>
src/foo/foo.py:17: note: use --pdb to drop into pdb

To Reproduce

Stand-alone example. Package needed:

first==2.0.2

Source code:

import logging
from typing import Any

from first import first

logger = logging.getLogger()
logger.setLevel(logging.INFO)


def update_rows(client, rows: list[dict[str, Any]]) -> None:
    response = client.update(rows)
    try:
        response_errors = response.errors
    except AttributeError:
        errors = []
    else:
        errors = first(
            (
                sorted(errors, key=int)
                for error in response_errors
                if (errors := error.context.get("objectWriteTraceId")) is not None
            ),
            default=[],
        )
    logger.info(
        "Number of contacts updated: %s, errors: %s", len(response.results), errors
    )

Your Environment

  • Mypy version used: 1.20.0+dev.92a78583b1cd0c9d0cc3966dfc534020128888ca (master)
  • Mypy command-line flags: --show-traceback
  • Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
mypy_path = "$MYPY_CONFIG_FILE_DIR/src"
platform = "linux"
python_version = "3.14"

[[tool.mypy.overrides]]
ignore_missing_imports = true
  • Python version used: Python 3.14.3
  • Operating system and version: macOS 15.7.3 (24G419)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mypy/checker.py at try_infer_partial_generic_type_from_assignment, where the traceback reaches del partial_types[var]. Run the standalone example with mypy --show-traceback to reproduce the KeyError. Done means the example no longer produces an INTERNAL ERROR or traceback.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.