GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing mail.python.org — [Python-Dev] Concerns about method overriding and subclassing with dataclasses [Python-Dev] Concerns about method overriding and subclassing with dataclassesEthan Furman ethan at stoneleaf.usFri Dec 29 14:37:38 EST 2017
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 dataclasses are billed as providing automatic methods. Overriding via method definition is very natural and > idiomatic. I don't really see how someone could accidentally override a dataclass method if methods were not generated > by the dataclass decorator that are already defined in the class at definition time. Accidental or not, the decorator should not be replacing methods defined by the class. > The second concern, which I came across more recently, is if I have a base class, and dataclasses inherit from this base > class, inherited __repr__ & co are silently overridden by dataclass. This is both unexpected, and also means I need to > pass a repr=False to each subclass' decorator to get correct behavior, which somewhat defeats the utility of > subclassing. Im not as sure a whole lot can be done about this though. 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 cases where a new, auto-generated, __repr__ is desired. -- ~Ethan~
More information about the Python-Dev mailing list |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |