Bug 1547730 - Use new inspection methods introduced in py3 but work in py2.7 for functions r=#build
☠☠ backed out by ee4b88439111 ☠ ☠
authorJustin Wood <Callek@gmail.com>
Mon, 15 Apr 2019 22:53:10 -0400
changeset 474153 59a1393697e0ac36ee62be71adf58a51904e02b6
parent 474152 61b8fcc639e087ced07e6dacf77fb66c1bb5f178
child 474154 cef492de6a7f54986925e2e2f56cbdcdad04a916
push id36023
push userncsoregi@mozilla.com
push dateThu, 16 May 2019 21:56:43 +0000
treeherdermozilla-central@786f094a30ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1547730
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1547730 - Use new inspection methods introduced in py3 but work in py2.7 for functions r=#build Differential Revision: https://phabricator.services.mozilla.com/D28112
python/mozbuild/mozbuild/configure/__init__.py
python/mozbuild/mozbuild/configure/lint.py
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -1058,17 +1058,17 @@ class ConfigureSandbox(dict):
         '''
         if not inspect.isfunction(func):
             raise TypeError("Unexpected type: '%s'" % type(func).__name__)
         if func in self._prepared_functions:
             return func
 
         glob = SandboxedGlobal(
             (k, v)
-            for k, v in six.iteritems(func.func_globals)
+            for k, v in six.iteritems(func.__globals__)
             if (inspect.isfunction(v) and v not in self._templates) or (
                 inspect.isclass(v) and issubclass(v, Exception))
         )
         glob.update(
             __builtins__=self.BUILTINS,
             __file__=self._paths[-1] if self._paths else '',
             __name__=self._paths[-1] if self._paths else '',
             os=self.OS,
@@ -1081,30 +1081,30 @@ class ConfigureSandbox(dict):
         # order will always be the same for a given function, and if it uses
         # variables from a closure that are changed after the function is
         # declared, depending when the function is executed, the value of the
         # variable can differ. For consistency, we force the function to use
         # the value from the earliest it can be run, which is at declaration.
         # Note this is not entirely bullet proof (if the value is e.g. a list,
         # the list contents could have changed), but covers the bases.
         closure = None
-        if func.func_closure:
+        if func.__closure__:
             def makecell(content):
                 def f():
                     content
-                return f.func_closure[0]
+                return f.__closure__[0]
 
             closure = tuple(makecell(cell.cell_contents)
-                            for cell in func.func_closure)
+                            for cell in func.__closure__)
 
         new_func = self.wraps(func)(types.FunctionType(
-            func.func_code,
+            func.__code__,
             glob,
             func.__name__,
-            func.func_defaults,
+            func.__defaults__,
             closure
         ))
         @self.wraps(new_func)
         def wrapped(*args, **kwargs):
             if func in self._imports:
                 self._apply_imports(func, glob)
             return new_func(*args, **kwargs)
 
--- a/python/mozbuild/mozbuild/configure/lint.py
+++ b/python/mozbuild/mozbuild/configure/lint.py
@@ -82,37 +82,37 @@ class LintSandbox(ConfigureSandbox):
         # argument, and the `raise` line is on the line given as argument.
 
         offset = line - firstline
         # co_lnotab is a string where each pair of consecutive character is
         # (chr(byte_increment), chr(line_increment)), mapping bytes in co_code
         # to line numbers relative to co_firstlineno.
         # If the offset we need to encode is larger than 255, we need to split it.
         co_lnotab = (chr(0) + chr(255)) * (offset / 255) + chr(0) + chr(offset % 255)
-        code = thrower.func_code
+        code = thrower.__code__
         code = types.CodeType(
             code.co_argcount,
             code.co_nlocals,
             code.co_stacksize,
             code.co_flags,
             code.co_code,
             code.co_consts,
             code.co_names,
             code.co_varnames,
             filename,
             funcname,
             firstline,
             co_lnotab
         )
         thrower = types.FunctionType(
             code,
-            thrower.func_globals,
+            thrower.__globals__,
             funcname,
-            thrower.func_defaults,
-            thrower.func_closure
+            thrower.__defaults__,
+            thrower.__closure__
         )
         thrower(exception)
 
     def _check_dependencies(self, obj):
         if isinstance(obj, CombinedDependsFunction) or obj in (self._always,
                                                                self._never):
             return
         func, glob = self.unwrap(obj._func)
@@ -149,17 +149,17 @@ class LintSandbox(ConfigureSandbox):
         if isinstance(obj, DependsFunction):
             if obj in (self._always, self._never):
                 return False
             func, glob = self.unwrap(obj._func)
             # We allow missing --help dependencies for functions that:
             # - don't use @imports
             # - don't have a closure
             # - don't use global variables
-            if func in self._has_imports or func.func_closure:
+            if func in self._has_imports or func.__closure__:
                 return True
             for op, arg, _ in disassemble_as_iter(func):
                 if op in ('LOAD_GLOBAL', 'STORE_GLOBAL'):
                     # There is a fake os module when one is not imported,
                     # and it's allowed for functions without a --help
                     # dependency.
                     if arg == 'os' and glob.get('os') is self.OS:
                         continue
@@ -264,20 +264,20 @@ class LintSandbox(ConfigureSandbox):
         while frame and frame.f_code.co_name != self.option_impl.__name__:
             frame = frame.f_back
         e = ConfigureError(
             '`help` should contain "{}" because of non-constant default'
             .format(rule))
         self._raise_from(e, frame.f_back if frame else None)
 
     def unwrap(self, func):
-        glob = func.func_globals
+        glob = func.__globals__
         while func in self._wrapped:
-            if isinstance(func.func_globals, SandboxedGlobal):
-                glob = func.func_globals
+            if isinstance(func.__globals__, SandboxedGlobal):
+                glob = func.__globals__
             func = self._wrapped[func]
         return func, glob
 
     def wraps(self, func):
         def do_wraps(wrapper):
             self._wrapped[wrapper] = func
             return wraps(func)(wrapper)
         return do_wraps
@@ -296,17 +296,17 @@ class LintSandbox(ConfigureSandbox):
         imports = set()
         for _from, _import, _as in self._imports.get(func, ()):
             if _as:
                 imports.add(_as)
             else:
                 what = _import.split('.')[0]
                 imports.add(what)
         for op, arg, line in disassemble_as_iter(func):
-            code = func.func_code
+            code = func.__code__
             if op == 'LOAD_GLOBAL' and \
                     arg not in glob and \
                     arg not in imports and \
                     arg not in glob['__builtins__'] and \
                     arg not in code.co_varnames[:code.co_argcount]:
                 # Raise the same kind of error as what would happen during
                 # execution.
                 e = NameError("global name '{}' is not defined".format(arg))