I've used code along the lines of:
thing_with_dataclass_like_semantics = dataclasses.dataclass
# define thing_with_dataclass_like_semantics
with moderate success.
I do sort of agree with Paul: to the extent that libraries have exact
dataclass semantics, they shouldn't need to exist (or can use the above
trick), and to the extent that they have different semantics, this proposal
would fall short (or get very complicated). And I do think there are a
variety of semantics here, e.g. https://github.com/python/cpython/pull/17322
On Fri, 23 Apr 2021 at 23:26, Paul Bryan
If such libraries were able to implement their data objects as dataclasses, would such a PEP be necessary?
On Sat, 2021-04-24 at 06:12 +0000, Eric Traut wrote:
PEP 557 introduced the dataclass to the Python stdlib. Several popular libraries (including attrs, pydantic, and various libraries that support database ORMs such as django and edgedb) have behaviors that are similar to dataclass, but these behaviors cannot be described using standard type annotations.
To work around this limitation, mypy custom plugins have been developed for many of these libraries, but these plugins don't work with other type checkers, linters or language servers. They are also costly to maintain for library authors, and they require that Python developers know about the existence of these plugins and download and configure them within their environment.
I've been exploring ways to extend support for dataclass semantics to other other libraries in a standardized manner. I've posted a [proposal in the form of a proto-PEP]( https://github.com/microsoft/pyright/blob/master/specs/dataclass_transforms.... ).
The latest versions of pylance and pyright implement this proposal as a proof of concept. It was relatively easy to implement (on the order of a couple hundred lines of code), and I assume that it would be similarly easy for other type checkers to add this support.
I've created a [github discussion and feedback forum]( https://github.com/microsoft/pyright/discussions/1782), and I welcome feedback on the proposal. I've already been in contact with the maintainers of attrs and pydantic. They are generally supportive, and I've incorporated their initial input into the latest draft of the proposal.
-- Eric Traut Contributor to Pyright & Pylance Microsoft Corp. _______________________________________________ Typing-sig mailing list -- email@example.com To unsubscribe send an email to firstname.lastname@example.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: email@example.com
_______________________________________________ Typing-sig mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: firstname.lastname@example.org