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

PEP 681: Rejected Ideas cleanup #2488

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions pep-0681.rst
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,6 @@ As this is not broadly applicable to dataclass libraries, this
additional logic is not accommodated with this proposal, so
users of Django would need to explicitly declare the ``id`` field.

This limitation may make it impractical to use the
``dataclass_transform`` mechanism with Django.

Class-wide default values
-------------------------

Expand All @@ -714,32 +711,29 @@ We chose not to support this feature, since it is specific to
SQLAlchemy. Users can manually set ``default=None`` on these fields
instead.

Open Issues
===========

``converter`` field descriptor parameter
----------------------------------------

The attrs library supports a ``converter`` field descriptor parameter,
which is a callable that is called by the generated
which is a ``Callable`` that is called by the generated
``__init__`` method to convert the supplied value to some other
desired value. This is tricky to support since the parameter type in
the synthesized __init__ method needs to accept uncovered values, but
the resulting field is typed according to the output of the converter.
the synthesized ``__init__`` method needs to accept uncovered values,
but the resulting field is typed according to the output of the
converter.

There may be no good way to support this because there's not enough
information to derive the type of the input parameter. We currently
have two ideas:
Some aspects of this issue are detailed in a
`Pyright discussion <#converters_>`_.

1. Add support for a ``converter`` field descriptor parameter but then
use the Any type for the corresponding parameter in the __init__
method.
There may be no good way to support this because there's not enough
information to derive the type of the input parameter. One possible
solution would be to add support for a ``converter`` field descriptor
parameter but then use the ``Any`` type for the corresponding
parameter in the ``__init__`` method.

2. Say that converters are unsupported and recommend that attrs users
avoid them.
We chose not to support this feature and recommend that attrs users
avoid converters.

Some aspects of this issue are detailed in a
`Pyright discussion <#converters_>`_.

References
==========
Expand Down