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

[1.1 backport] [dataclass_transform] include __dataclass_fields__ in transformed types (#14752) #14769

Merged
merged 1 commit into from
Feb 23, 2023

Commits on Feb 23, 2023

  1. [1.1 backport] [dataclass_transform] include __dataclass_fields__ in …

    …transformed types (python#14752)
    
    `dataclasses` uses a `__dataclass_fields__` attribute on each class to
    mark that it is a dataclass, and Typeshed checks for this attribute in
    its stubs for functions like `dataclasses.is_dataclass` and
    `dataclasses.asdict`.
    
    In python#14667, I mistakenly removed this attribute for classes transformed
    by a `dataclass_transform`. This was due to a misinterpretation of PEP
    681 on my part; after rereading the [section on dataclass
    semantics](https://peps.python.org/pep-0681/#dataclass-semantics), it
    says:
    
    > Except where stated otherwise in this PEP, classes impacted by
    `dataclass_transform`, either by inheriting from a class that is
    decorated with `dataclass_transform` or by being decorated with a
    function decorated with `dataclass_transform`, are assumed to behave
    like stdlib dataclass.
    
    The PEP doesn't seem to state anything about `__dataclass_fields__` or
    the related functions as far as I can tell, so we should assume that
    transforms should match the behavior of `dataclasses.dataclass` in this
    regard and include the attribute. This also matches the behavior of
    Pyright, which the PEP defines as the reference implementation.
    
    (cherry picked from commit 54635de)
    wesleywright authored and cdce8p committed Feb 23, 2023
    Configuration menu
    Copy the full SHA
    00584e1 View commit details
    Browse the repository at this point in the history