Abstract dataclasses and dataclass fields
![](https://secure.gravatar.com/avatar/4f6079564f02b87e4c0989585439eb39.jpg?s=120&d=mm&r=g)
I am finding that it would be useful to be able to define a dataclass that is an abstract base class and define some of its field as abstract. As I am typing this, I realize that I could presumably write some code to implement what I'm asking for. Maybe it is a good enough idea to make part of the standard API in any case though? I'm thinking that a field would be made abstract by passing `abstract=True` as an argument to `dataclasses.field()`.
![](https://secure.gravatar.com/avatar/2828041405aa313004b6549acf918228.jpg?s=120&d=mm&r=g)
On 12/21/2023 4:38 PM, Steve Jorgensen wrote:
I am finding that it would be useful to be able to define a dataclass that is an abstract base class and define some of its field as abstract.
As I am typing this, I realize that I could presumably write some code to implement what I'm asking for. Maybe it is a good enough idea to make part of the standard API in any case though? I'm thinking that a field would be made abstract by passing `abstract=True` as an argument to `dataclasses.field()`.
You're better off discussing this on discuss.python.org as this mailing list is basically dead. And when you do post over there, please provide an example. It's not clear what would happen in the generated code if abstract=True. Eric
![](https://secure.gravatar.com/avatar/1b108f4b1167bbf9d35404290f53e1eb.jpg?s=120&d=mm&r=g)
On 12/23/23 02:09, Eric V. Smith via Python-ideas wrote:
On 12/21/2023 4:38 PM, Steve Jorgensen wrote:
I am finding that it would be useful to be able to define a dataclass that is an abstract base class and define some of its field as abstract.
As I am typing this, I realize that I could presumably write some code to implement what I'm asking for. Maybe it is a good enough idea to make part of the standard API in any case though? I'm thinking that a field would be made abstract by passing `abstract=True` as an argument to `dataclasses.field()`.
You're better off discussing this on discuss.python.org as this mailing list is basically dead.
It can't be dead - you're here!
And when you do post over there, please provide an example. It's not clear what would happen in the generated code if abstract=True.
-- Regards =dn
![](https://secure.gravatar.com/avatar/d67ab5d94c2fed8ab6b727b62dc1b213.jpg?s=120&d=mm&r=g)
On Sat, 23 Dec 2023 at 07:13, DL Neil via Python-ideas <python-ideas@python.org> wrote:
On 12/23/23 02:09, Eric V. Smith via Python-ideas wrote:
On 12/21/2023 4:38 PM, Steve Jorgensen wrote:
I am finding that it would be useful to be able to define a dataclass that is an abstract base class and define some of its field as abstract.
As I am typing this, I realize that I could presumably write some code to implement what I'm asking for. Maybe it is a good enough idea to make part of the standard API in any case though? I'm thinking that a field would be made abstract by passing `abstract=True` as an argument to `dataclasses.field()`.
You're better off discussing this on discuss.python.org as this mailing list is basically dead.
It can't be dead - you're here!
Eh! He says he's not dead! ChrisA
![](https://secure.gravatar.com/avatar/1b108f4b1167bbf9d35404290f53e1eb.jpg?s=120&d=mm&r=g)
On 12/23/23 09:51, Chris Angelico wrote:
On Sat, 23 Dec 2023 at 07:13, DL Neil via Python-ideas <python-ideas@python.org> wrote:
On 12/23/23 02:09, Eric V. Smith via Python-ideas wrote:
On 12/21/2023 4:38 PM, Steve Jorgensen wrote:
I am finding that it would be useful to be able to define a dataclass that is an abstract base class and define some of its field as abstract.
As I am typing this, I realize that I could presumably write some code to implement what I'm asking for. Maybe it is a good enough idea to make part of the standard API in any case though? I'm thinking that a field would be made abstract by passing `abstract=True` as an argument to `dataclasses.field()`.
You're better off discussing this on discuss.python.org as this mailing list is basically dead.
It can't be dead - you're here!
Eh! He says he's not dead!
"I think therefore..."? You'll be telling me next, that this is a virtual-communication! -- Regards =dn
![](https://secure.gravatar.com/avatar/1b108f4b1167bbf9d35404290f53e1eb.jpg?s=120&d=mm&r=g)
On 12/22/23 10:38, Steve Jorgensen wrote:
I am finding that it would be useful to be able to define a dataclass that is an abstract base class and define some of its field as abstract.
As I am typing this, I realize that I could presumably write some code to implement what I'm asking for. Maybe it is a good enough idea to make part of the standard API in any case though? I'm thinking that a field would be made abstract by passing `abstract=True` as an argument to `dataclasses.field()`.
What is the use-case? Please provide an example (in English). Please outline some sample code. After a bit of reading-around*, thoughts seemed to coalesce around two, separate but inextricably-linked, components which the code-reader/-reviewer will be required to comprehend: 1 that there is an ABC 2 that there is/are concrete implementations of that ABC (aside from instances of the latter) Accordingly, why the need for the ABC to be a dataclass? Is there some reason why this use-case cannot implement a dataclass of a 'standard' ABC? (following my policy of being 'basically-lazy', I like using dataclasses. However, sometimes they are not the best tool for the job!) * web.refs of possible interest: https://docs.python.org/3/library/abc.html [noting the >=v3.3 use of properties (cf "field") https://stackoverflow.com/questions/51079503/dataclasses-and-property-decora... https://florimond.dev/en/posts/2018/10/reconciling-dataclasses-and-propertie... Let's also state, and discard, the idea that there is no need (from Python's perspective) for an ABC at all, creating a super-(data)class, and inheriting from there 'works' - but doesn't help comprehension. -- Regards =dn
participants (5)
-
Chris Angelico
-
DL Neil
-
Eric V. Smith
-
Greg Ewing
-
Steve Jorgensen