Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Interface.__eq__" ignores the "Interface" semantics and renders dynamic interface definitions unreliable #218

Closed
d-maurer opened this issue Oct 1, 2020 · 5 comments

Comments

@d-maurer
Copy link
Contributor

d-maurer commented Oct 1, 2020

Interface.__eq__ is only based on __name__ and __module__. This results in a very surprising notion of equality as the following code demonstrates:

>>> from zope.interface import Interface
>>> class I(Interface):
...   def f(): pass
... 
>>> I1 = I
>>> class I: pass
... 
>>> I1 == I
True

i.e. the interface I1 is considered equal to the "normal" (non Interface) class I.

This renders local (i.e. in a function body) interface definitions unreliable as
#216 (comment)
(and following comments) demonstrates. The resulting errors can be non-deterministic and very difficult to analyze.

@jamadden explains in #216 that __eq__ is defined as it is in order to allow interfaces to be used as keys in BTrees. This may justify the definition however due to the potentially very difficult errors which may result from local interface definitions it should be clearly documented (which currently is not the case) with a big warning regarding the implication for local interface definitions (or overridden interface definitions as in the example above).

@jensens
Copy link
Member

jensens commented Oct 1, 2020

Taking into account that hashing and equality are called very very often in the code, I am also +1 for good documentation but keeping the current state of implementation. Performance wise it works fine.

@jamadden
Copy link
Member

jamadden commented Oct 1, 2020

Because the example is unrealistic, ignores pickling/persistence, only results in problems in extremely rare corner cases, and has been the status quo for a decade, I do not consider this to be a significant problem.

I consider the existing documentation adequate. I feel there is no need for "a big warning."

@jensens
Copy link
Member

jensens commented Oct 1, 2020

I would not add a big warning, just I think it would be good to mention explicit that (like in the context of mocking for testing):

class A1:
    def a1():
        class IA(Interface):
            pass

class A2:
    def a2():
        class IA(Interface):
            pass

will let you run into problems.

@d-maurer
Copy link
Contributor Author

d-maurer commented Oct 1, 2020 via email

@d-maurer
Copy link
Contributor Author

The Interface (more generally Specification) equality definition and its potential caveats are now covered by the (upcoming) documentation (--> #220).

kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Jan 19, 2021
5.2.0 (2020-11-05)

==================

- Add documentation section ``Persistency and Equality``
  (`openembedded#218 <https://github.com/zopefoundation/zope.interface/issues/218>`_).

- Create arm64 wheels.

- Add support for Python 3.9.

Signed-off-by: Zang Ruochen <zangrc.fnst@cn.fujitsu.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Jan 19, 2021
5.2.0 (2020-11-05)

==================

- Add documentation section ``Persistency and Equality``
  (`openembedded#218 <https://github.com/zopefoundation/zope.interface/issues/218>`_).

- Create arm64 wheels.

- Add support for Python 3.9.

Signed-off-by: Zang Ruochen <zangrc.fnst@cn.fujitsu.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Jan 19, 2021
5.2.0 (2020-11-05)

==================

- Add documentation section ``Persistency and Equality``
  (`openembedded#218 <https://github.com/zopefoundation/zope.interface/issues/218>`_).

- Create arm64 wheels.

- Add support for Python 3.9.

Signed-off-by: Zang Ruochen <zangrc.fnst@cn.fujitsu.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Jan 20, 2021
5.2.0 (2020-11-05)

==================

- Add documentation section ``Persistency and Equality``
  (`openembedded#218 <https://github.com/zopefoundation/zope.interface/issues/218>`_).

- Create arm64 wheels.

- Add support for Python 3.9.

Signed-off-by: Zang Ruochen <zangrc.fnst@cn.fujitsu.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
halstead pushed a commit to openembedded/meta-openembedded that referenced this issue Jan 20, 2021
5.2.0 (2020-11-05)

==================

- Add documentation section ``Persistency and Equality``
  (`#218 <https://github.com/zopefoundation/zope.interface/issues/218>`_).

- Create arm64 wheels.

- Add support for Python 3.9.

Signed-off-by: Zang Ruochen <zangrc.fnst@cn.fujitsu.com>
Acked-by: Trevor Gamblin <trevor.gamblin@windriver.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants