PY2/3 fix action function sigs to skip docstrings
authorWilliam Deegan <bill@baddogconsulting.com>
Wed, 2 Aug 2017 01:56:27 +0000 (18:56 -0700)
committerWilliam Deegan <bill@baddogconsulting.com>
Wed, 2 Aug 2017 01:56:27 +0000 (18:56 -0700)
src/engine/SCons/Action.py
src/engine/SCons/ActionTests.py

index 4449bea85288925cc6246b80ed5d35206b8abcf5..d6fe30b4f66c9f6bac39bf5b035600041409d385 100644 (file)
@@ -210,7 +210,7 @@ def _object_contents(obj):
                         return bytearray(repr(obj), 'utf-8')
 
 
-def _code_contents(code):
+def _code_contents(code, docstring=None):
     """Return the signature contents of a code object.
 
     By providing direct access to the code object of the
@@ -257,7 +257,8 @@ def _code_contents(code):
     # function. Note that we have to call _object_contents on each
     # constants because the code object of nested functions can
     # show-up among the constants.
-    z = [_object_contents(cc) for cc in code.co_consts]
+
+    z = [_object_contents(cc) for cc in code.co_consts[1:]]
     contents.extend(b',(')
     contents.extend(bytearray(',', 'utf-8').join(z))
     contents.extend(b')')
@@ -295,7 +296,7 @@ def _function_contents(func):
     func.__closure__  - None or a tuple of cells that contain bindings for the function's free variables.
     """
 
-    contents = [_code_contents(func.__code__)]
+    contents = [_code_contents(func.__code__, func.__doc__)]
 
     # The function contents depends on the value of defaults arguments
     if func.__defaults__:
index cf423076e134989e62058e4d1d11b8ee6b597989..9d856c9bcfc81477192fea813a6dd5b9313a80d7 100644 (file)
@@ -1430,9 +1430,9 @@ class CommandGeneratorActionTestCase(unittest.TestCase):
 
         # Since the python bytecode has per version differences, we need different expected results per version
         func_matches = {
-            (2,7) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,5) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,6) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00S\x00),(),()'),
+            (2,7) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,5) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,6) : bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
         }
 
         meth_matches = [
@@ -1593,15 +1593,15 @@ class FunctionActionTestCase(unittest.TestCase):
             pass
 
         func_matches = {
-            (2,7) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,5) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,6) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00S\x00),(),()'),
+            (2,7) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,5) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,6) : bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
         }
 
         meth_matches = {
-            (2,7) : bytearray(b'1, 1, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,5) : bytearray(b'1, 1, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,6) : bytearray(b'1, 1, 0, 0,(N.),(),(d\x00S\x00),(),()'),
+            (2,7) : bytearray(b'1, 1, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,5) : bytearray(b'1, 1, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,6) : bytearray(b'1, 1, 0, 0,(),(),(d\x00S\x00),(),()'),
         }
 
         def factory(act, **kw):
@@ -1818,9 +1818,9 @@ class LazyActionTestCase(unittest.TestCase):
 
 
         func_matches = {
-            (2,7) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,5) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00S),(),()'),
-            (3,6) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00S\x00),(),()'),
+            (2,7) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,5) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
+            (3,6) : bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
         }
 
         meth_matches = [
@@ -2058,9 +2058,9 @@ class ObjectContentsTestCase(unittest.TestCase):
 
         # Since the python bytecode has per version differences, we need different expected results per version
         expected = {
-            (2,7) : bytearray(b'3, 3, 0, 0,(A test function),(),(|\x00\x00S),(),()'),
-            (3,5) : bytearray(b'3, 3, 0, 0,(A test function),(),(|\x00\x00S),(),()'),
-            (3,6) : bytearray(b'3, 3, 0, 0,(A test function),(),(|\x00S\x00),(),()'),
+            (2,7) : bytearray(b'3, 3, 0, 0,(),(),(|\x00\x00S),(),()'),
+            (3,5) : bytearray(b'3, 3, 0, 0,(),(),(|\x00\x00S),(),()'),
+            (3,6) : bytearray(b'3, 3, 0, 0,(),(),(|\x00S\x00),(),()'),
         }
 
         c = SCons.Action._function_contents(func1)
@@ -2078,9 +2078,9 @@ class ObjectContentsTestCase(unittest.TestCase):
 
         # Since the python bytecode has per version differences, we need different expected results per version
         expected = {
-            (2,7): bytearray(b"{TestClass:__main__}[[[(<type \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<type \'object\'>,))]]]]{{1, 1, 0, 0,(N.,a,b),(a,b),(d\x01\x00|\x00\x00_\x00\x00d\x02\x00|\x00\x00_\x01\x00d\x00\x00S),(),(),2, 2, 0, 0,(N.),(),(d\x00\x00S),(),()}}{{{a=a,b=b}}}"),
-            (3,5): bytearray(b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(N.,a,b),(a,b),(d\x01\x00|\x00\x00_\x00\x00d\x02\x00|\x00\x00_\x01\x00d\x00\x00S),(),(),2, 2, 0, 0,(N.),(),(d\x00\x00S),(),()}}{{{a=a,b=b}}}"),
-            (3,6): bytearray(b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(N.,a,b),(a,b),(d\x01|\x00_\x00d\x02|\x00_\x01d\x00S\x00),(),(),2, 2, 0, 0,(N.),(),(d\x00S\x00),(),()}}{{{a=a,b=b}}}"),
+            (2,7): bytearray(b"{TestClass:__main__}[[[(<type \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<type \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01\x00|\x00\x00_\x00\x00d\x02\x00|\x00\x00_\x01\x00d\x00\x00S),(),(),2, 2, 0, 0,(),(),(d\x00\x00S),(),()}}{{{a=a,b=b}}}"),
+            (3,5): bytearray(b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01\x00|\x00\x00_\x00\x00d\x02\x00|\x00\x00_\x01\x00d\x00\x00S),(),(),2, 2, 0, 0,(),(),(d\x00\x00S),(),()}}{{{a=a,b=b}}}"),
+            (3,6): bytearray(b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01|\x00_\x00d\x02|\x00_\x01d\x00S\x00),(),(),2, 2, 0, 0,(),(),(d\x00S\x00),(),()}}{{{a=a,b=b}}}"),
         }
 
         assert c == expected[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected \n"+"\n"+repr(expected[sys.version_info[:2]])
@@ -2093,9 +2093,9 @@ class ObjectContentsTestCase(unittest.TestCase):
 
         # Since the python bytecode has per version differences, we need different expected results per version
         expected = {
-            (2,7) : bytearray(b'0, 0, 0, 0,(Hello, World!,N.),(),(d\x00\x00GHd\x01\x00S)'),
-            (3,5) : bytearray(b'0, 0, 0, 0,(Hello, World!,N.),(print),(e\x00\x00d\x00\x00\x83\x01\x00\x01d\x01\x00S)'),
-            (3,6) : bytearray(b'0, 0, 0, 0,(Hello, World!,N.),(print),(e\x00d\x00\x83\x01\x01\x00d\x01S\x00)'),
+            (2,7) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00GHd\x01\x00S)'),
+            (3,5) : bytearray(b'0, 0, 0, 0,(N.),(print),(e\x00\x00d\x00\x00\x83\x01\x00\x01d\x01\x00S)'),
+            (3,6) : bytearray(b'0, 0, 0, 0,(N.),(print),(e\x00d\x00\x83\x01\x01\x00d\x01S\x00)'),
         }
 
         assert c == expected[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected \n"+"\n"+expected[sys.version_info[:2]]