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

Migrate to typing.dataclass_transform() #1157

Closed
superbobry opened this issue Jun 26, 2023 · 3 comments
Closed

Migrate to typing.dataclass_transform() #1157

superbobry opened this issue Jun 26, 2023 · 3 comments

Comments

@superbobry
Copy link
Contributor

attrs type stubs seem to use a non-standard pyright extension instead of the API described in PEP-681:

attrs/src/attr/__init__.pyi

Lines 106 to 121 in 4461e2c

# Static type inference support via __dataclass_transform__ implemented as per:
# https:/microsoft/pyright/blob/1.1.135/specs/dataclass_transforms.md
# This annotation must be applied to all overloads of "define" and "attrs"
#
# NOTE: This is a typing construct and does not exist at runtime. Extensions
# wrapping attrs decorators should declare a separate __dataclass_transform__
# signature in the extension module using the specification linked above to
# provide pyright support.
def __dataclass_transform__(
*,
eq_default: bool = True,
order_default: bool = False,
kw_only_default: bool = False,
frozen_default: bool = False,
field_descriptors: Tuple[Union[type, Callable[..., Any]], ...] = (()),
) -> Callable[[_T], _T]: ...

This makes it difficult for other type checkers and similar tools to consume these type stubs without mirroring the pyright extension.

Would you accept a PR replacing all usages of __dataclass_transform__() with typing.dataclass_transform()? We can use typing_extensions to get dataclass_transform() on Python < 3.11.

@Tinche
Copy link
Member

Tinche commented Jun 26, 2023

Don't see why not, feel free to proceed with a PR. I believe our use of dataclass_transform predates the PEP and the typing implementation.

@superbobry
Copy link
Contributor Author

Yes, IIRC that feature was incubated in pyright and then proposed&accepted as a PEP. Will send a PR soon.

@hynek
Copy link
Member

hynek commented Jul 7, 2023

fixed by #1158

@hynek hynek closed this as completed Jul 7, 2023
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

No branches or pull requests

3 participants