Constructing a SpecBuildInterface from another gives no inconsistent MRO (#7457)

fixes #7239
This commit is contained in:
Massimiliano Culpo
2018-03-12 09:07:08 +01:00
committed by Todd Gamblin
parent a4ed76c207
commit a1c8ce82f2
2 changed files with 34 additions and 1 deletions

View File

@@ -458,5 +458,17 @@ class ObjectWrapper(object):
def __init__(self, wrapped_object):
wrapped_cls = type(wrapped_object)
wrapped_name = wrapped_cls.__name__
self.__class__ = type(wrapped_name, (type(self), wrapped_cls), {})
# If the wrapped object is already an ObjectWrapper, or a derived class
# of it, adding type(self) in front of type(wrapped_object)
# results in an inconsistent MRO.
#
# TODO: the implementation below doesn't account for the case where we
# TODO: have different base classes of ObjectWrapper, say A and B, and
# TODO: we want to wrap an instance of A with B.
if type(self) not in wrapped_cls.__mro__:
self.__class__ = type(wrapped_name, (type(self), wrapped_cls), {})
else:
self.__class__ = type(wrapped_name, (wrapped_cls,), {})
self.__dict__ = wrapped_object.__dict__