-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Common part for all class decorators. | |
"""Common hook for applying class decorators. |
There was a problem hiding this comment.
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)
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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 |
I've noticed that
TypedDict
andNamedTuple
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
!