Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor class decorator: this enables type_check_only support for TypedDict and NamedTuple #16469

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

sobolevn
Copy link
Member

I've noticed that TypedDict and NamedTuple classes are special cased during semantic analyzisys. They had their own logic for class-level decorators. This is fine, but we need some common ground.

As a side-effect, they can now be type_check_only!

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM (minor comment about a docstring below)

mypy/semanal.py Outdated
def analyze_class_decorator_common(
self, defn: ClassDef, info: TypeInfo, decorator: Expression
) -> None:
"""Common part for all class decorators.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""Common part for all class decorators.
"""Common hook for applying class decorators.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! Thanks, except it is not a hook. By hooks we often mean things like self.plugin.get_customize_class_mro_hook(defn.fullname)

mypy/semanal.py Outdated Show resolved Hide resolved
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@sobolevn sobolevn merged commit 023eb41 into python:master Nov 13, 2023
18 checks passed
@Avasam
Copy link
Contributor

Avasam commented Mar 14, 2024

Nice! pywin32 has some named-tuples it generates dynamically but doesn't expose. https://github.com/python/typeshed/blob/main/stubs/pywin32/win32/lib/win32gui_struct.pyi

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