diff mbox series

[5/6] data_smart: directly check for methodpool functions in context lookup

Message ID 20230801143813.2206785-5-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 6cac1eac51efa9a54e8457f60ea1ea0e604c50b7
Headers show
Series [1/6] tests.data: add test for inline python calling a def'd function | expand

Commit Message

Richard Purdie Aug. 1, 2023, 2:38 p.m. UTC
From: Christopher Larson <kergoth@gmail.com>

We previously checked for the existence of the 'func' flag to determine
if we should avoid looking up in the metadata. This was done to ensure
the user gets the function for 'def' python functions rather than their
string contents. We can sidestep the metadata lookup and check our
function context directly, instead.

Signed-off-by: Christopher Larson <kergoth@gmail.com>
---
 lib/bb/data_smart.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
index fe0bacd13b..0128a5bb17 100644
--- a/lib/bb/data_smart.py
+++ b/lib/bb/data_smart.py
@@ -154,19 +154,20 @@  class VariableParse:
             return str(value)
 
 class DataContext(dict):
-    excluded = set([i for i in dir(builtins) if not i.startswith('_')] + ['bb', 'os', 'oe'])
+    excluded = set([i for i in dir(builtins) if not i.startswith('_')] + ['oe'])
 
     def __init__(self, metadata, **kwargs):
         self.metadata = metadata
         dict.__init__(self, **kwargs)
         self['d'] = metadata
+        self.context = set(bb.utils.get_context())
 
     def __missing__(self, key):
-        if key in self.excluded:
+        if key in self.excluded or key in self.context:
             raise KeyError(key)
 
         value = self.metadata.getVar(key)
-        if value is None or self.metadata.getVarFlag(key, 'func', False):
+        if value is None:
             raise KeyError(key)
         else:
             return value