-
-
Notifications
You must be signed in to change notification settings - Fork 146
Description
Python's MRO (Method Resolution Order), a.k.a. the C3 algorithm, should control how an attribute is looked up in a class hierarchy. However, if those classes inherit from configurations.Configuration, the attribute that is found by C3 changes. This appears to be a result of the ConfigurationBase metaclass, which copies attributes from parent classes onto the child class. See the examples below, which differ only by whether BaseConfig inherits from Configuration.
import configurations
class BaseConfig(configurations.Configuration):
DEBUG = False
class TestConfig(BaseConfig):
DEBUG = True
class ServiceConfig(BaseConfig):
...
class TestServiceConfig(ServiceConfig, TestConfig):
...
assert TestServiceConfig.DEBUG == True # assertion failsclass BaseConfig:
DEBUG = False
class TestConfig(BaseConfig):
DEBUG = True
class ServiceConfig(BaseConfig):
...
class TestServiceConfig(ServiceConfig, TestConfig):
...
assert TestServiceConfig.DEBUG == True # assertion passesI find it surprising that the value of the DEBUG attribute is not what it should be, as defined by the C3 algorithm. I don't think the ConfigurationBase class should be copying attributes onto child classes. If it didn't, then the C3 algorithm would find the correct value for the DEBUG attribute.