Skip to content

Fix qualified names for lambdas in class headers - #112

Merged
alexmojaki merged 1 commit into
alexmojaki:masterfrom
edsonsims:fix/class-header-qualnames
Oct 29, 2026
Merged

alexmojaki merged 1 commit into
alexmojaki:masterfrom
edsonsims:fix/class-header-qualnames

Conversation

@edsonsims

Copy link
Copy Markdown
Contributor

Source.code_qualname() currently adds the class being defined to lambdas in class decorators, base expressions and metaclass keywords. For example, a module-level @lambda cls: cls reports Decorated.<lambda> instead of the function's actual <lambda> name.

Visit those header expressions in the enclosing scope while retaining the existing handling of class bodies, function headers and type parameters. The regressions compare reported names with actual func.__qualname__ values at module, function and nested-class scope, including Python 3.12+ generic class headers.

Validation on Python 3.13.1:

  • Full suite with EXECUTING_SLOW_TESTS=1: 254 passed, 6 existing skips.
  • New regression selection: 24 passed; the original source fails 15 cases and passes 9 controls.
  • Mypy 2.1.0 and the configured Ruff formatting hook pass.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the class-header qualified-name fix.

No open issues 🎉

What changed in this PR

Fixes Source.code_qualname() so lambdas in class headers use the enclosing scope rather than incorrectly including the class being defined.

Changes:

  • Visits class decorators, bases, and keywords outside the class scope while preserving class-body and type-parameter handling.
  • Adds regression coverage across module, function, and nested-class scopes, plus Python 3.12+ generic class headers.
File Description
tests/​test_qualname_class_headers.py Compares reported qualified names with runtime __qualname__ values and checks existing behavior.
executing/​executing.py Separates class-header traversal from class-scope traversal.

Review effort: Balanced

@alexmojaki

Copy link
Copy Markdown
Owner

Thanks!

@alexmojaki
alexmojaki merged commit 5c15c1d into alexmojaki:master Oct 29, 2026
10 checks passed
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.

3 participants