python / python/mypy

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

Abierto
#20,792 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

crash
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza en mypy/checker.py, en try_infer_partial_generic_type_from_assignment, donde el traceback llega a del partial_types[var]. Ejecuta el ejemplo independiente con mypy --show-traceback para reproducir el KeyError. Se considera terminado cuando el ejemplo ya no produce un INTERNAL ERROR ni un traceback.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.