smarie/python-autoclass

independent @autoeq with different behaviour than the one included in @autodict

smarie opened this issue · 3 comments

Currently, only @autodict (or @autoclass with default option autodict=True) generates a __eq__ implementation, which is based on dictionary equality. It would be better to

  • have an independent way of generating the equality method (@autoeq),
  • and to change @autodict behaviour: rather than implementing a dictionary directly on the object, it could instead provide a as_dict() method which would be that view.

This is even more true since with the current implementation of @autodict, dict is added to the class hierarchy of the class and therefore counterintuitive things happen such as:

from autoclass import autoclass

@autoclass
class MyClass:
    def __init__(self, x, y, z):
        pass

a = MyClass(0,1,2)
s = set(a)  # s is equal to {'z', 'x', 'y'} !!!

Afterthoughts... the example above was not so counter intuitive. Indeed if one wants to create a set with a inside, he/she would rather do {a}, which provides the expected result.

So this might actually never be really needed... let's keep it open and wait for feedback if any.

Wont fix. Current behaviour seems ok.