InterfaceClass __cmp method obtains module name incorrectly
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
zope.interface |
Fix Released
|
Medium
|
Unassigned |
Bug Description
InterfaceClass provides custom __gt__ and __lt__ methods based on a method called __cmp, which tries to compare a (interface name, module name) tuple for the two given interfaces. However, this code tries to retrieve the module name via getattr(
from x import IContentish
from y import IContentish as IContentish2
>>> IContentish < IContentish2
False
>>> IContentish > IContentish2
False
>>> IContentish == IContentish2
False
This has ugly implications when interfaces are used as BTree keys, as the ordering is not trichotomous.
I am attaching a patch which I believe fixes the issue.
Changed in zope.interface: | |
importance: | Undecided → Medium |
The original code is clearly wrong: it is written on the assumption that an interface's '__module__'' attribute is a module object, rather than its dotted name.