]> granicus.if.org Git - python/commitdiff
SF bug #1048870: call arg of lambda not updating
authorRaymond Hettinger <python@rcn.com>
Sun, 24 Oct 2004 00:10:06 +0000 (00:10 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 24 Oct 2004 00:10:06 +0000 (00:10 +0000)
Lib/test/test_compile.py
Misc/NEWS
Python/compile.c

index 5011d0368524dc6dc20b7fd20e5755632669cf7a..c567fa432abb6efafc3c6463a94c003819296063 100644 (file)
@@ -252,6 +252,15 @@ if 1:
         for stmt in fail:
             self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
 
+    def test_for_distinct_code_objects(self):
+        # SF bug 1048870
+        def f():
+            f1 = lambda x=1: x
+            f2 = lambda x=2: x
+            return f1, f2
+        f1, f2 = f()
+        self.assertNotEqual(id(f1.func_code), id(f2.func_code))
+
 def test_main():
     test_support.run_unittest(TestSpecifics)
 
index e12621de7a22c95cc8478d6166ba4d32c8a87b60..d0a5af5bd61bedf6706ff94366a75b9fe8cc52ba 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,7 +37,10 @@ Core and builtins
 Extension Modules
 -----------------
 
-...
+- Bug #1048870:  the compiler now generates distinct code objects for
+  functions with identical bodies.  This was producing confusing
+  traceback messages which pointed to the function where the code
+  object was first defined rather than the function being executed.
 
 Library
 -------
index dc636c0ea73fb24be01c28fb16570b0737957200..dfb94d38e31d8607cf6f03acddf8d99a49c480ae 100644 (file)
@@ -261,6 +261,8 @@ code_compare(PyCodeObject *co, PyCodeObject *cp)
        if (cmp) return (cmp<0)?-1:1;
        cmp = co->co_flags - cp->co_flags;
        if (cmp) return (cmp<0)?-1:1;
+       cmp = co->co_firstlineno - cp->co_firstlineno;
+       if (cmp) return (cmp<0)?-1:1;
        cmp = PyObject_Compare(co->co_code, cp->co_code);
        if (cmp) return cmp;
        cmp = PyObject_Compare(co->co_consts, cp->co_consts);