python / python/mypy

dmypy's `--use-fine-grained-cache` crashes with `KeyError` on namespace packages

Open
#20,519 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is possibly related to #10735.

To Reproduce & Traceback

Create a minimal project as follows:

project/
  mypy.ini
      [mypy]
      files = src/
  src/
    pkg/
      __init__.py
      nspkg/
        mod.py
            a: int = ""

Reproduce with these steps:

  1. Navigate to project/
  2. $ mypy --cache-fine-grained
    src/pkg/nspkg/mod.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
    
  3. $ dmypy run -- --use-fine-grained-cache
    Daemon started
    Success: no issues found in 2 source files
    
    (I don't think this should say Success given the errors from Step 2., but that's a separate issue.)
  4. Change mod.py, e.g. modify the sole line to a: int = "a"
  5. Run the daemon twice:
    • $ dmypy run -- --use-fine-grained-cache
      src/pkg/nspkg/mod.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
      
    • $ dmypy run -- --use-fine-grained-cache
      Daemon crashed!
      Traceback (most recent call last):
        File ".../mypy/dmypy_server.py", line 237, in serve
          ...
        File ".../mypy/dmypy_server.py", line 768, in find_reachable_changed_modules
       worklist.append(BuildSource(graph[dep].path, graph[dep].id, followed=True))
                                   ~~~~~^^^^^
      KeyError: 'pkg.nspkg'
      

Your Environment

  • Mypy version used: 1.19.1
  • Python version used: Python 3.13

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

Reproduce the namespace-package case with dmypy and --use-fine-grained-cache, then inspect dmypy_server.py around find_reachable_changed_modules and line 768, where the traceback looks up pkg.nspkg in graph. Use the listed commands to verify the daemon no longer crashes on the second run and still reports the assignment error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.