Test: vpp_papi_provider. __getattr__ 21/18021/3
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Tue, 5 Mar 2019 12:30:04 +0000 (04:30 -0800)
committerOle Trøan <otroan@employees.org>
Tue, 5 Mar 2019 15:44:44 +0000 (15:44 +0000)
Replace custom __getattr__ with custom __getattribute__.

Change-Id: Ib96176abc07eefedba305ed874621001a810eb0d
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
test/vpp_papi_provider.py

index c21d8c2..2188ed3 100644 (file)
@@ -174,11 +174,15 @@ class VppPapiProvider(object):
             return self.api(apifn, d)
         return f
 
-    def __getattr__(self, name):
+    def __getattribute__(self, name):
         try:
-            return getattr(self, name)
-        except:
-            return self.factory(name, getattr(self.papi, name))
+            method = super(VppPapiProvider, self).__getattribute__(name)
+        except AttributeError:
+            method = self.factory(name, getattr(self.papi, name))
+            # lazily load the method so we don't need to call factory
+            # again for this name.
+            setattr(self, name, method)
+        return method
 
     def connect(self):
         """Connect the API to VPP"""