[Python-Dev] Concerns about method overriding and subclassing with dataclasses (original) (raw)

Eric V. Smith eric at trueblade.com
Sun Jan 21 21:50:52 EST 2018


On 1/7/2018 12:25 PM, Guido van Rossum wrote:

On Sun, Jan 7, 2018 at 9:09 AM, Eric V. Smith <eric at trueblade.com_ _<mailto:eric at trueblade.com>> 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 <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 flag to control their generation, but python will use "not eq" if you don't provide ne. I need to think through what happens if the user only provides eq: does dataclasses do nothing, does it add ne, and how does this interact with a base class that does provide ne. Maybe dataclasses should only ever provide eq and always assume Python's default for ne kicks in? If that's not acceptable (maybe there are cases where a user did write an explicit ne that needs to be overridden) I would recommend the following rule: - If there's an eq, don't do anything (regardless of whether there's an ne) - If there no eq but there is an ne, generate eq but don't generate ne - If neither exists, generate both

I've added my proposal on issue 32513: https://bugs.python.org/issue32513#msg310392

It's long, so I won't repeat it here. The only really confusing part is hash and its interaction with eq.

Eric.



More information about the Python-Dev mailing list