Skip to content

Preserve imported placeholder names for dynamic class hooks - #22327

Open
ayushin wants to merge 1 commit into
python:masterfrom
ang-ee:codex/upstream-placeholder-fullname-20261030
Open

ayushin wants to merge 1 commit into
python:masterfrom
ang-ee:codex/upstream-placeholder-fullname-20261030

Conversation

@ayushin

@ayushin ayushin commented Oct 30, 2026

Copy link
Copy Markdown

Fixes #22326.

An imported placeholder can be the receiver of a dynamic-class factory while semantic analysis is still resolving an import cycle. Preserve its qualified name on the NameExpr so the factory's plugin hook can run. Without it, the generated base is rejected as a variable and inherited methods become Any.

The production change is one line in SemanticAnalyzer.bind_name_expr. The regression extends the existing from_queryset test plugin to defer incomplete classes, publish a placeholder, and reuse the resolved class on later passes. It checks both inherited method types and rejection of a missing method, without Django or a third-party plugin dependency.

Validation against master 7da2058491422897ecdbf61261d2540bb10099a0 on Python 3.14.6:

  • The new regression fails with the test changes alone and passes with the production change.
  • python -m pytest -n2 mypy/test/testcheck.py::TypeCheckSuite::check-custom-plugin.test --tb=short -q: 65 passed.
  • Pinned Ruff 0.14.3, Black 26.1.0 and git diff --check pass for the changed code.

Prepared with AI assistance from a downstream manager-typing failure. No downstream package or release configuration is included.

@github-actions

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

1 participant

⌂ Proxy