Computing The Resolution Order (Priority)¶
Just as Python classes have a method resolution order that determines which implementation of a method gets used when inheritance is used, interfaces have a resolution order that determines their ordering when searching for adapters.
That order is computed by
zope.interface.ro.ro. This is an
internal module not generally needed by a user of
but its documentation can be helpful to understand how orders are
Compute a resolution order for an object and its bases.
Changed in version 5.0: The resolution order is now based on the same C3 order that Python uses for classes. In complex instances of multiple inheritance, this may result in a different ordering.
In older versions, the ordering wasn’t required to be C3 compliant, and for backwards compatibility, it still isn’t. If the ordering isn’t C3 compliant (if it is inconsistent), zope.interface will make a best guess to try to produce a reasonable resolution order. Still (just as before), the results in such cases may be surprising.
Due to the change in 5.0, certain environment variables can be used to control errors and warnings about inconsistent resolution orders. They are listed in priority order, with variables at the bottom generally overriding variables above them.
- If this is set to “1”, then if there is at least one inconsistent resolution
order discovered, a warning (
InconsistentResolutionOrderWarning) will be issued. Use the usual warning mechanisms to control this behaviour. The warning text will contain additional information on debugging.
- If this is set to “1”, then zope.interface will log information about each inconsistent resolution order discovered, and keep those details in memory in this module for later inspection.
- If this is set to “1”, any attempt to use
ro()that would produce a non-C3 ordering will fail by raising
There are two environment variables that are independent.
- If this is set to “1”, then if the C3 resolution order is different from the legacy resolution order for any given object, a message explaining the differences will be logged. This is intended to be used for debugging complicated IROs.
- If this is set to “1”, then the C3 resolution order will not be used. The
legacy IRO will be used instead. This is a temporary measure and will be removed in the
future. It is intended to help during the transition.
ro(C) → list¶
Compute the precedence list (mro) according to C3.
Returns: A fresh
Changed in version 5.0.0: Add the strict, log_changed_ro and use_legacy_ro keyword arguments. These are provisional and likely to be removed in the future. They are most useful for testing.
The error raised when an invalid IRO is requested in strict mode.
The warning issued when an invalid IRO is requested.