Skip to content

Conversation

@cburroughs
Copy link

When a stub imports from a module without stubs (e.g., protobuf stubs importing from google.protobuf when protobuf stubs aren't installed), the import is suppressed but a cross-ref is cached. On cache reload, resolving the cross-ref fails along the lines of:

AssertionError: Cannot find module for google

This occurs because the cross-ref points to a module that was suppressed and therefore never loaded into manager.modules.

The fix passes the set of suppressed modules to fixup_module() and checks if a cross-ref points to a suppressed module before attempting lookup. If so, a placeholder node is used instead.

Before this change on my test setup (see #20655) with 128 shards iterating through different dependency combination, 29 crashed with this error. With the change 0 do so. The reproduction at Qiskit/qiskit-serverless#1787 also passes for me with this change.

Fixes #16214

Disclaimer: I don't have prior familiarity with the mypy codebase and this change was heavily LLM assisted.

When a stub imports from a module without stubs (e.g., protobuf stubs
importing from google.protobuf when protobuf stubs aren't installed),
the import is suppressed but a cross-ref is cached. On cache reload,
resolving the cross-ref fails along the lines of:

    AssertionError: Cannot find module for google

This occurs because the cross-ref points to a module that was suppressed
and therefore never loaded into manager.modules.

The fix passes the set of suppressed modules to fixup_module() and
checks if a cross-ref points to a suppressed module before attempting
lookup. If so, a placeholder node is used instead.

Before this change on my test setup (see python#20655) with 128 shards
iterating through different dependency combination, 29 crashed with
this error.  With the change 0 do so.  The reproduction at
Qiskit/qiskit-serverless#1787 also passes for
me with this change.

Fixes python#16214

Disclaimer: I don't have prior familiarity with the mypy codebase and
this change was heavily LLM assisted.
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caching bug with --incremental --cache-dir combination causes AssertionError: Cannot find module

1 participant