FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactor class decorator: this enables `type_check_only` support for `TypedDict` and `NamedTuple` by sobolevn · Pull Request #16469 · python/mypy · GitHub

Repository navigation

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

Merged
sobolevn merged 3 commits into
python:masterfrom
sobolevn:refactor-class-decorator
Nov 13, 2023
Merged

sobolevn merged 3 commits into
python:masterfrom
sobolevn:refactor-class-decorator

Conversation

Copy link
Copy Markdown
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.

AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM (minor comment about a docstring below)

Comment thread 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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
"""Common part for all class decorators.
"""Common hook for applying class decorators.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread mypy/semanal.py Outdated

Copy link
Copy Markdown
Contributor

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

sobolevn merged commit 023eb41 into python:master Nov 13, 2023

Avasam commented Mar 14, 2024

Copy link
Copy Markdown
Contributor

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

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL