@@ -18,7 +18,6 @@ def __init__(self, name=None, **params):
1818 self .params = params
1919 if params is None :
2020 params = {}
21- self .extra_capability_checks = {}
2221 super (Model , self ).__init__ ()
2322 self .check_params ()
2423
@@ -39,16 +38,31 @@ def __init__(self, name=None, **params):
3938 extra_capability_checks = None
4039 """Optional extra checks of capabilities on a per-instance basis."""
4140
42- @property
43- def capabilities ( self ):
41+ @classmethod
42+ def get_capabilities ( cls ):
4443 """List the model's capabilities."""
4544 capabilities = []
46- for cls in self . __class__ .mro ():
47- if issubclass (cls , Capability ) and cls is not Capability \
48- and not issubclass (cls , Model ):
49- capabilities .append (cls . __name__ )
45+ for _cls in cls .mro ():
46+ if issubclass (_cls , Capability ) and _cls is not Capability \
47+ and not issubclass (_cls , Model ):
48+ capabilities .append (_cls )
5049 return capabilities
5150
51+ @property
52+ def capabilities (self ):
53+ return self .__class__ .get_capabilities ()
54+
55+ @property
56+ def failed_extra_capabilities (self ):
57+ """Check to see if instance passes its `extra_capability_checks`."""
58+ failed = []
59+ for capability , f_name in self .extra_capability_checks .items ():
60+ f = getattr (self , f_name )
61+ instance_capable = f ()
62+ if isinstance (self , capability ) and not instance_capable :
63+ failed .append (capability )
64+ return failed
65+
5266 def describe (self ):
5367 """Describe the model."""
5468 result = "No description available"
@@ -87,6 +101,17 @@ def is_match(self, match):
87101 result = True # Found by instance or name
88102 return result
89103
104+ def __getattr__ (self , attr ):
105+ try :
106+ result = super (Model , self ).__getattribute__ (attr )
107+ except AttributeError :
108+ try :
109+ result = self ._backend .__getattribute__ (attr )
110+ except :
111+ raise AttributeError ("Model %s has no attribute %s"
112+ % (self , attr ))
113+ return result
114+
90115 def __str__ (self ):
91116 """Return the model name."""
92117 return '%s' % self .name
0 commit comments