(original) (raw)
On Sun, Jan 7, 2018 at 9:09 AM, Eric V. Smith <eric@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
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
--Guido van Rossum (python.org/\~guido)