Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-02-02 Thread Sylvain MARIE
Rossum Envoyé : lundi 29 janvier 2018 20:44 À : George Leslie-Waksman <waks...@gmail.com> Cc : Eric V. Smith <e...@trueblade.com>; python-ideas <python-ideas@python.org> Objet : Re: [Python-ideas] Dataclasses, keyword args, and inheritance That's fair. Let me then qu

Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-29 Thread Guido van Rossum
That's fair. Let me then qualify my statement with "in the initial release". The initial release has enough functionality to deal with without considering your rather esoteric use case. (And I consider it esoteric because attrs has apparently never seen the need to solve it either.) We can

Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-29 Thread George Leslie-Waksman
Given I started this thread from a perspective of this is a feature that I would like because I need it, it feels a little dismissive to take attrs not having the feature to mean "there's no reason to try to implement this." On Mon, Jan 29, 2018 at 11:05 AM Guido van Rossum

Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-29 Thread George Leslie-Waksman
attrs' seems to also not allow mandatory attributes to follow optional one: In [14]: @attr.s ...: class Baz: ...: a = attr.ib(default=attr.Factory(list)) ...: b = attr.ib() ...: --- ValueError

Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-26 Thread George Leslie-Waksman
Even if we could inherit the setting, I would think that we would still want to require the code be explicit. It seems worse to implicitly require keyword only arguments for a class without giving any indication in the code. As it stands, the current implementation does not allow a later subclass

Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-25 Thread Eric V. Smith
I'm not completely opposed to this feature. But there are some cases to consider. Here's the first one that occurs to me: note that due to the way dataclasses work, it would need to be used everywhere down an inheritance hierarchy. That is, if an intermediate base class required it, all class

Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-24 Thread George Leslie-Waksman
It may be possible but it makes for pretty leaky abstractions and it's unclear what that custom __init__ should look like. How am I supposed to know what the replacement for default_factory is? Moreover, suppose I want one base class with an optional argument and a half dozen subclasses each with

Re: [Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-24 Thread Ivan Levkivskyi
It is possible to pass init=False to the decorator on the subclass (and supply your own custom __init__, if necessary): @dataclass class Foo: some_default: dict = field(default_factory=dict) @dataclass(init=False) # This works class Bar(Foo): other_field: int -- Ivan On 23 January

[Python-ideas] Dataclasses, keyword args, and inheritance

2018-01-22 Thread George Leslie-Waksman
The proposed implementation of dataclasses prevents defining fields with defaults before fields without defaults. This can create limitations on logical grouping of fields and on inheritance. Take, for example, the case: @dataclass class Foo: some_default: dict = field(default_factory=dict)