Skip to content

Fix/22326 placeholder qualified name - #22401

Closed
Rifa-111 wants to merge 5 commits into
python:masterfrom
Rifa-111:fix/22326-placeholder-qualified-name
Closed

Rifa-111 wants to merge 5 commits into
python:masterfrom
Rifa-111:fix/22326-placeholder-qualified-name

Conversation

@Rifa-111

@Rifa-111 Rifa-111 commented Nov 8, 2026 •

Copy link
Copy Markdown

Summary

Fixes #22326.

Preserve the fully qualified name of an imported symbol when SemanticAnalyzer.bind_name_expr encounters a PlaceholderNode during an import cycle.

Previously, the qualified name could be lost before a dynamic class hook resolved the referenced type, resulting in invalid-base-class errors and imprecise inferred types.

Changes

  • Semantic analysis: Preserve expr.fullname before processing an imported placeholder in mypy/semanal.py.
  • Dynamic class hook: Extend the existing test plugin to defer class generation until the referenced queryset type is resolved.
  • Regression coverage: Add testDynamicClassHookImportedPlaceholderCycle, covering cyclic imports, dynamically generated manager classes, inferred method return types and unknown-method diagnostics.

Verification

All 25 GitHub Actions checks passed on commit 6f2ce32, including the test suites, type checking, formatting and mypy_primer.

The regression test is included in test-data/unit/check-custom-plugin.test.

Attribution

This PR addresses the issue and core fix identified by @ayushin in #22326. The regression scenario and test-plugin changes were adapted from the reproduction shared in that issue.

AI assistance was used in preparing and iterating on this contribution.

Feedback on the implementation and regression coverage is welcome.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
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.

Imported placeholder names are lost before dynamic class hooks run

2 participants