Skip to content

Conversation

@JelleZijlstra
Copy link
Member

From PEP 681.

cc @erictraut @debonte

"""
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