python / python/mypy

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

Ouverte
#20,792 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

crash
Langage dominant
Python
Étoiles
20.6k
Forks
3.3k
Métriques de merge des PR
Métriques de PR en attente

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)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans mypy/checker.py à try_infer_partial_generic_type_from_assignment, là où le traceback atteint del partial_types[var]. Exécutez l’exemple autonome avec mypy --show-traceback pour reproduire le KeyError. C’est terminé lorsque l’exemple ne produit plus d’INTERNAL ERROR ni de traceback.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
devtools
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
55/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.