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.0 backport] minimal implementation of dataclass_transform (#14523) #14532

Merged
merged 1 commit into from
Jan 29, 2023

Conversation

hauntsaninja
Copy link
Collaborator

This is a very simple first step to implementing PEP 0681, which will allow MyPy to recognize user-defined types that behave similarly to dataclasses.

This initial implementation is very limited: we only support decorator-style use of typing.dataclass_transform and do not support passing additional options to the transform (such as freeze or init).

Within MyPy, we add a new is_dataclass_transform field to FuncBase which is populated during semantic analysis. When we check for plugin hooks later, we add new special cases to use the existing dataclasses plugin if a class decorator is marked with is_dataclass_transform. Ideally we would use a proper plugin API; the hacky special case here can be replaced in subsequent iterations.

Co-authored-by: Wesley Wright wesleyw@dropbox.com

…ython#14523)

This is a very simple first step to implementing [PEP
0681](https://peps.python.org/pep-0681/#decorator-function-example),
which will allow MyPy to recognize user-defined types that behave
similarly to dataclasses.

This initial implementation is very limited: we only support
decorator-style use of `typing.dataclass_transform` and do not support
passing additional options to the transform (such as `freeze` or
`init`).

Within MyPy, we add a new `is_dataclass_transform` field to `FuncBase`
which is populated during semantic analysis. When we check for plugin
hooks later, we add new special cases to use the existing dataclasses
plugin if a class decorator is marked with `is_dataclass_transform`.
Ideally we would use a proper plugin API; the hacky special case here
can be replaced in subsequent iterations.

Co-authored-by: Wesley Wright <wesleyw@dropbox.com>
@hauntsaninja hauntsaninja mentioned this pull request Jan 26, 2023
17 tasks
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@hauntsaninja hauntsaninja merged commit b7c850c into python:release-1.0 Jan 29, 2023
@hauntsaninja hauntsaninja deleted the release-1.0 branch January 29, 2023 20:03
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.

2 participants