Skip to content

Fix crash on partially typed namespace package#20742

Open
ilevkivskyi wants to merge 2 commits intopython:masterfrom
ilevkivskyi:fix-half-typed-ns
Open

Fix crash on partially typed namespace package#20742
ilevkivskyi wants to merge 2 commits intopython:masterfrom
ilevkivskyi:fix-half-typed-ns

Conversation

@ilevkivskyi
Copy link
Member

Fixes #16214
Closes #20658

The root cause is similar to the issue fixed by #19044, when there are multiple packages in google namespace, some with py.typed, some without. As a result, there can be a situation where we first find the untyped one, and mark ancestor (i.e. google) as suppressed, but then we find the typed one and actually add ancestor (i.e. google) to the graph. This creates a situation where we write some references to google in cache, while it may not be loaded on the warm run, thus causing a crash.

My solution is simple: un-suppress namespace ancestors if there is at least one package that needs them, so that the build graph is consistent.

Unfortunately, this uncovers another (pre-existing) bug where # type: ignores are not handled correctly on warm runs, similar to #20105. In any case, I am going to submit a separate PR for this bug (I think there may be a simple fix for it).

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

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