Remove discussion of alternate form (#2386)

This commit is contained in:
Erik De Bonte 2022-03-07 15:26:17 -08:00 committed by GitHub
parent dfdf510680
commit f52151b9d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 33 deletions

View File

@ -549,36 +549,6 @@ decorated with ``dataclass_transform`` is in use.
`ignored by dataclass mechanisms <#class-var_>`_.
Alternate form
--------------
To avoid delaying adoption of this proposal until after
``dataclass_transform`` has been added to the ``typing`` module, type
checkers may support the alternative form ``__dataclass_transform__``.
This form can be defined locally without any reliance on the
``typing`` or ``typing_extensions`` modules, and allows immediate
adoption of this specification by library authors. Type checkers that
have not yet adopted this specification will retain their current
behavior.
To use this alternate form, library authors should include the
following declaration within their type stubs or source files:
.. code-block:: python
_T = TypeVar("_T")
def __dataclass_transform__(
*,
eq_default: bool = True,
order_default: bool = False,
kw_only_default: bool = False,
field_descriptors: tuple[type | Callable[..., Any], ...] = (),
) -> Callable[[_T], _T]:
# If used within a stub file, the following implementation can
# be replaced with "...".
return lambda a: a
Undefined behavior
------------------
@ -590,13 +560,14 @@ behavior is undefined. Library authors should avoid these scenarios.
Reference Implementation
========================
The `Pyright <#pyright_>`_ type checker supports the
``__dataclass_transform__`` `alternate form`_. Pyright's
`Pyright <#pyright_>`_ contains the reference implementation of type
checker support for ``dataclass_transform``. Pyright's
``dataClasses.ts`` `source file <#pyright-impl_>`_ would be a good
starting point for understanding the implementation.
The `attrs <#attrs-usage_>`_ and `pydantic <#pydantic-usage_>`_
libraries are using the ``__dataclass_transform__`` `alternate form`_.
libraries are using ``dataclass_transform`` and serve as real-world
examples of its usage.
Rejected Ideas