
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