Skip to content

Fixes #21030: Undefined names used as decorators on top of TypedDict are not reported#21049

Open
pranavmanglik wants to merge 1 commit intopython:masterfrom
pranavmanglik:master
Open

Fixes #21030: Undefined names used as decorators on top of TypedDict are not reported#21049
pranavmanglik wants to merge 1 commit intopython:masterfrom
pranavmanglik:master

Conversation

@pranavmanglik
Copy link

This PR ensures that decorators applied to a TypedDict class definition are correctly analyzed for undefined names.

Previously, the semantic analyzer's special-case handling for TypedDict (analyze_typeddict_classdef) was returning early without visiting the decorators list in the ClassDef. This caused mypy to silently ignore invalid names, attributes, or subscripted expressions used as decorators on these classes.
Changes

mypy/semanal.py: Updated analyze_typeddict_classdef to iterate through defn.decorators and call accept(self) on each. This triggers the standard semantic analysis and name-resolution logic for those expressions.

test-data/unit/check-typeddict.test: Added a new data-driven test case testTypedDictDecoratorUndefinedNames covering:

    Simple undefined names (@abc)

    Undefined attributes (@efg.hij)

    Undefined names within subscripts (@klm[nop])

Checklist:

[x] Read the [Contributing Guidelines](https://github.com/python/mypy/blob/master/CONTRIBUTING.md)

[x] Add tests for all changed behaviour.

[x] Make sure CI passes.

@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.

1 participant