python / python/mypy

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

Aperta
#20,792 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

crash
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in mypy/checker.py, in try_infer_partial_generic_type_from_assignment, dove il traceback raggiunge del partial_types[var]. Esegui l’esempio autonomo con mypy --show-traceback per riprodurre il KeyError. Il lavoro è completato quando l’esempio non produce più un INTERNAL ERROR o un traceback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.