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

add dataclass_transform #1054

Merged
merged 3 commits into from
Feb 2, 2022
Merged

add dataclass_transform #1054

merged 3 commits into from
Feb 2, 2022

Conversation

JelleZijlstra
Copy link
Member

From PEP 681.

cc @erictraut @debonte

typing_extensions/src/typing_extensions.py Outdated Show resolved Hide resolved
typing_extensions/src/typing_extensions.py Outdated Show resolved Hide resolved

"""
def decorator(cls_or_fn):
cls_or_fn.__dataclass_transform__ = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to use this pattern used in final?

        try:
            f.__final__ = True
        except (AttributeError, TypeError):
            # Skip the attribute silently if it is not writable.
            # AttributeError happens if the object has __slots__ or a
            # read-only property, TypeError if it's a builtin class.
            pass
        return f

Copy link
Member Author

Choose a reason for hiding this comment

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

I was more careful there because we added the behavior later after the decorator was already in the wild, and I didn't want to accidentally break something. Here, we're adding a new decorator, so I think it makes sense to start with the simpler behavior and adjust it only if there's an actual need.

@JelleZijlstra JelleZijlstra merged commit 59e5918 into python:master Feb 2, 2022
@JelleZijlstra JelleZijlstra deleted the pep681 branch February 2, 2022 17:46
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request Apr 23, 2022
Copied from typing-extensions (python/typing#1054, python/typing#1120).

Documentation is intentionally omitted, so we can focus on getting the
runtime part in before the feature freeze.
JelleZijlstra added a commit to python/cpython that referenced this pull request Apr 26, 2022
Copied from typing-extensions (python/typing#1054, python/typing#1120).

Documentation is intentionally omitted, so we can focus on getting the
runtime part in before the feature freeze.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants