Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-21 Thread Eric V. Smith
On 1/7/2018 12:25 PM, Guido van Rossum wrote: On Sun, Jan 7, 2018 at 9:09 AM, Eric V. Smith > wrote: On 1/3/2018 1:17 PM, Eric V. Smith wrote: I’ll open an issue after I have time to read this thread and comment on it. https://bugs.python.org

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-07 Thread Guido van Rossum
On Sun, Jan 7, 2018 at 9:09 AM, Eric V. Smith wrote: > On 1/3/2018 1:17 PM, Eric V. Smith wrote: > >> I’ll open an issue after I have time to read this thread and comment on >> it. >> > > https://bugs.python.org/issue32513 > I need to think though how __eq__ and __ne__ work, as well as the orderi

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-07 Thread Eric V. Smith
On 1/3/2018 1:17 PM, Eric V. Smith wrote: I’ll open an issue after I have time to read this thread and comment on it. https://bugs.python.org/issue32513 I need to think though how __eq__ and __ne__ work, as well as the ordering operators. My specific concern with __ne__ is that there's one f

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 2:11 PM, Eric V. Smith wrote: On 1/5/2018 2:09 PM, Guido van Rossum wrote: I'm normally no big fan of things that take either a class or an instance, but since fields() does this, I think is_dataclass() should to. And that's the name I'd choose. OK on the pseudo-fields. Sounds goo

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 2:09 PM, Guido van Rossum wrote: I'm normally no big fan of things that take either a class or an instance, but since fields() does this, I think is_dataclass() should to. And that's the name I'd choose. OK on the pseudo-fields. Sounds good. I'll open a bpo issue. Eric. On Fri, J

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Guido van Rossum
I'm normally no big fan of things that take either a class or an instance, but since fields() does this, I think is_dataclass() should to. And that's the name I'd choose. OK on the pseudo-fields. On Fri, Jan 5, 2018 at 11:06 AM, Eric V. Smith wrote: > On 1/5/2018 12:58 PM, Guido van Rossum wrote

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 12:58 PM, Guido van Rossum wrote: Hm. I don't know that people will conclude that checking for a dataclass is an anti-pattern. They'll probably just invent a myriad of different hacks like the one you showed. I recommend making it public. I'm trying to track down the original discu

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Guido van Rossum
Hm. I don't know that people will conclude that checking for a dataclass is an anti-pattern. They'll probably just invent a myriad of different hacks like the one you showed. I recommend making it public. I still worry a bit about ClassVar and InitVar being potentially useful but I concede I have

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 11:24 AM, Guido van Rossum wrote: On Fri, Jan 5, 2018 at 5:08 AM, Eric V. Smith > wrote: On 1/2/2018 12:01 AM, Guido van Rossum wrote: Yes, there's a class variable (__dataclass_fields__) that identifies the parent fields. The PEP doesn

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Guido van Rossum
On Fri, Jan 5, 2018 at 5:08 AM, Eric V. Smith wrote: > On 1/2/2018 12:01 AM, Guido van Rossum wrote: > >> Yes, there's a class variable (__dataclass_fields__) that identifies the >> parent fields. The PEP doesn't mention this or the fact that special >> methods (like __repr__ and __init__) can te

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/2/2018 12:01 AM, Guido van Rossum wrote: On Mon, Jan 1, 2018 at 8:50 PM, Ethan Smith > wrote: On Mon, Jan 1, 2018 at 5:03 PM, Chris Barker mailto:chris.bar...@noaa.gov>> wrote: On Sat, Dec 30, 2017 at 7:27 AM, Stephen J. Turnbull mailto:turnbu

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-03 Thread Eric V. Smith
I’ll open an issue after I have time to read this thread and comment on it. -- Eric. > On Jan 3, 2018, at 12:31 PM, Ivan Levkivskyi wrote: > > I like the Guido's proposal, i.e. > > if '__repr__' not in cls.__dict__: > ... # generate the method > > etc. I didn't find an issue to

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-03 Thread Ivan Levkivskyi
I like the Guido's proposal, i.e. if '__repr__' not in cls.__dict__: ... # generate the method etc. I didn't find an issue to track this. Maybe we should open one? -- Ivan ___ Python-Dev mailing list Python-Dev@python.org https://mail.pyth

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-02 Thread Stephen J. Turnbull
Chris Barker writes: > are we only talking about __repr__ here ??? I am, because I haven't thought about the other methods, except to note I find it hard to imagine a use case *for me* that would require any of them. That sorta disqualifies me from comment. ;-) I assumed others were talking ab

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-01 Thread Guido van Rossum
On Mon, Jan 1, 2018 at 8:50 PM, Ethan Smith wrote: > > > On Mon, Jan 1, 2018 at 5:03 PM, Chris Barker > wrote: > >> On Sat, Dec 30, 2017 at 7:27 AM, Stephen J. Turnbull < >> turnbull.stephen...@u.tsukuba.ac.jp> wrote: >> >>> Just use the simple rule that a new >>> __repr__ is generated unless

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-01 Thread Chris Barker
On Mon, Jan 1, 2018 at 7:50 PM, Ethan Smith wrote: > > Will you get the "right" __repr__ now if you derive a datacalss from a >> dataclass? That would be a nice feature. >> > > > The __repr__ will be generated by the child dataclass unless the user > overrides it. So I believe this is the "right"

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-01 Thread Ethan Smith
On Mon, Jan 1, 2018 at 5:03 PM, Chris Barker wrote: > On Sat, Dec 30, 2017 at 7:27 AM, Stephen J. Turnbull < > turnbull.stephen...@u.tsukuba.ac.jp> wrote: > >> Just use the simple rule that a new >> __repr__ is generated unless provided in the dataclass. >> > > are we only talking about __repr_

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-01 Thread Chris Barker
On Sat, Dec 30, 2017 at 7:27 AM, Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Just use the simple rule that a new > __repr__ is generated unless provided in the dataclass. > are we only talking about __repr__ here ??? I interpretted Guido's proposal as being about all me

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-30 Thread Stephen J. Turnbull
Ethan Furman writes: > Good point. So auto-generate a new __repr__ if: > > - one is not provided, and > - existing __repr__ is either: >- object.__repr__, or >- a previous dataclass __repr__ -0.5 I'm with Guido here. Just use the simple rule that a new __repr__ is generated unles

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-30 Thread Eric V. Smith
I’m traveling until next week, and haven’t had time to read any of these emails. I’ll look at them when I return. -- Eric. > On Dec 30, 2017, at 5:20 AM, Raymond Hettinger > wrote: > > >> On Dec 29, 2017, at 4:52 PM, Guido van Rossum wrote: >> >> I still think it should overrides anything

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-30 Thread Raymond Hettinger
> On Dec 29, 2017, at 4:52 PM, Guido van Rossum wrote: > > I still think it should overrides anything that's just inherited but nothing > that's defined in the class being decorated. This has the virtue of being easy to explain, and it will help with debugging by honoring the code proximate t

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Smith
Okay, I think Guido's proposal is a good compromise. I already have a branch of dataclasses that should implement that behavior, so perhaps it was meant to be. :) ~>Ethan Smith On Fri, Dec 29, 2017 at 5:13 PM, Nick Coghlan wrote: > > > On 30 Dec. 2017 11:01 am, "Ethan Smith" wrote: > > > > On

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Nick Coghlan
On 30 Dec. 2017 11:01 am, "Ethan Smith" wrote: On Fri, Dec 29, 2017 at 4:52 PM, Guido van Rossum wrote: > I still think it should overrides anything that's just inherited but > nothing that's defined in the class being decorated. > > Could you explain why you are of this opinion? Is it a conc

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Guido van Rossum
No, I am concerned about the rule being too complex to explain, and about surprising effects when the base changes (action at a distance). I also don't necessarily think "we all agree" that what attrs does is wrong, but the rule I propose seems reasonable. On Dec 29, 2017 5:58 PM, "Ethan Smith"

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Furman
On Fri, Dec 29, 2017 at 12:30 PM, Ethan Furman wrote: > Good point. So auto-generate a new __repr__ if: > > - one is not provided, and > - existing __repr__ is either: > - object.__repr__, or > - a previous dataclass __repr__ > > And if the auto default doesn't work for one's use-case, use th

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Smith
On Fri, Dec 29, 2017 at 4:52 PM, Guido van Rossum wrote: > I still think it should overrides anything that's just inherited but > nothing that's defined in the class being decorated. > > Could you explain why you are of this opinion? Is it a concern about complexity of implementation? > On Dec

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Smith
attrs just silently overwrites any user provided __repr__ unless you provide repr=False to attr.s. I think we can all agree that if nothing else, silently overwriting unconditionally is not what we want for dataclasses. On Fri, Dec 29, 2017 at 4:38 PM, Nathaniel Smith wrote: > On Fri, Dec 29, 2

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Guido van Rossum
I still think it should overrides anything that's just inherited but nothing that's defined in the class being decorated. On Dec 29, 2017 5:43 PM, "Nathaniel Smith" wrote: > On Fri, Dec 29, 2017 at 12:30 PM, Ethan Furman wrote: > > Good point. So auto-generate a new __repr__ if: > > > > - one

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Nathaniel Smith
On Fri, Dec 29, 2017 at 12:30 PM, Ethan Furman wrote: > Good point. So auto-generate a new __repr__ if: > > - one is not provided, and > - existing __repr__ is either: > - object.__repr__, or > - a previous dataclass __repr__ > > And if the auto default doesn't work for one's use-case, use th

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Smith
On Fri, Dec 29, 2017 at 12:30 PM, Ethan Furman wrote: > On 12/29/2017 11:55 AM, Ethan Smith wrote: > >> On Fri, Dec 29, 2017 at 11:37 AM, Ethan Furman wrote: >> > > It is possible to determine whether an existing __repr__ is from 'object' >>> >> >> or not, and only provide one if that is the case

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Furman
On 12/29/2017 11:55 AM, Ethan Smith wrote: On Fri, Dec 29, 2017 at 11:37 AM, Ethan Furman wrote: It is possible to determine whether an existing __repr__ is from 'object' >> or not, and only provide one if that is the case. I think that should be >> the default, with 'repr = True' for those

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Smith
On Fri, Dec 29, 2017 at 11:37 AM, Ethan Furman wrote: > On 12/29/2017 02:23 AM, Ethan Smith wrote: > > The first is that needing both a keyword and method is duplicative and >> unnecessary. Eric agreed it was a hassle, but >> felt it was justified considering someone may accidentally override a >

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Furman
On 12/29/2017 02:23 AM, Ethan Smith wrote: The first is that needing both a keyword and method is duplicative and unnecessary. Eric agreed it was a hassle, but felt it was justified considering someone may accidentally override a dataclass method. I disagree with this point of view as dataclas

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Antoine Pitrou
On Fri, 29 Dec 2017 11:12:11 -0800 Ethan Smith wrote: > > > Agreed as well. If I make the effort of having a dataclass inherit > > from a base class, I probably don't want the base class' methods to be > > silently overriden by machine-generated methods. Of course, that can > > be worked around

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Guido van Rossum
But you always inherit __repr__, from object. The base class might also itself be a dataclass. I think it should only skip when the decorated class itself defines __repr__. On Dec 29, 2017 3:47 AM, "Antoine Pitrou" wrote: > On Fri, 29 Dec 2017 02:23:56 -0800 > Ethan Smith wrote: > > > > In a fe

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Smith
On Fri, Dec 29, 2017 at 2:45 AM, Antoine Pitrou wrote: > On Fri, 29 Dec 2017 02:23:56 -0800 > Ethan Smith wrote: > > > > In a few cases I want to override the repr of the AST nodes. I wrote a > > __repr__ and ran the code but lo and behold I got a type error. I > couldn't > > override it. I quic

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Antoine Pitrou
On Fri, 29 Dec 2017 02:23:56 -0800 Ethan Smith wrote: > > In a few cases I want to override the repr of the AST nodes. I wrote a > __repr__ and ran the code but lo and behold I got a type error. I couldn't > override it. I quickly learned that one needs to pass a keyword to the > dataclass decora

[Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017-12-29 Thread Ethan Smith
Hello all, I've recently been experimenting with dataclasses. They totally rock! A lot of the boilerplate for the AST I've designed in Python is automatically taken care of, it's really great! However, I have a few concerns about the implementation. In a few cases I want to override the repr of t