-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report on too-convoluted interface/implementation hierarchies
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""It is not always possible to consistently inject complicated | ||
interface hierarchy into implementation MRO. We warn about such occurances. | ||
By itself, both interface hierarchy and implementation hierarchies are | ||
consistent, but combining them is impossible - resulting inheritance graph | ||
become unsortable. | ||
""" | ||
import zope.interface | ||
|
||
class ICreature(zope.interface.Interface): pass | ||
class ISwimmable(zope.interface.Interface): pass | ||
class IReptilia(ICreature): pass | ||
class ICrocodile(ICreature, ISwimmable): pass | ||
|
||
@zope.interface.implementer(ISwimmable) | ||
class Swimmable: pass | ||
@zope.interface.implementer(IReptilia) | ||
class Reptilia(Swimmable): pass | ||
@zope.interface.implementer(ICrocodile) | ||
class Crocodile(Reptilia): pass | ||
|
||
|
||
def main() -> None: | ||
croc = Crocodile() | ||
print(croc) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
""" | ||
<output> | ||
bad_mro.py:19: error: Unable to calculate a consistent MRO: cannot merge class hierarchies: | ||
bad_mro.py:19: error: -> ['__main__.Crocodile', '__main__.Reptilia', '__main__.Swimmable', '__main__.ISwimmable', '__main__.IReptilia', '__main__.ICreature', 'zope.interface.Interface', 'builtins.object'] | ||
bad_mro.py:19: error: -> ['__main__.ICrocodile', '__main__.ICreature', '__main__.ISwimmable', 'zope.interface.Interface', 'builtins.object'] | ||
</output> | ||
""" |