]> granicus.if.org Git - python/commitdiff
Issue #29337: Fixed possible BytesWarning when compare the code objects.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 24 Jan 2017 18:49:26 +0000 (20:49 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 24 Jan 2017 18:49:26 +0000 (20:49 +0200)
Warnings could be emitted at compile time.

Lib/test/test_compile.py
Misc/NEWS
Objects/codeobject.c

index 824e843914c1231a5c2ae23f1337b217bab8e3ad..4ea66a488f44c9ebfe211e97263d3eac8e9cfde4 100644 (file)
@@ -634,6 +634,7 @@ if 1:
             f1 = ns['f1']
             f2 = ns['f2']
             self.assertIsNot(f1.__code__, f2.__code__)
+            self.assertNotEqual(f1.__code__, f2.__code__)
             self.check_constant(f1, const1)
             self.check_constant(f2, const2)
             self.assertEqual(repr(f1()), repr(const1))
@@ -642,6 +643,8 @@ if 1:
         check_different_constants(0, 0.0)
         check_different_constants(+0.0, -0.0)
         check_different_constants((0,), (0.0,))
+        check_different_constants('a', b'a')
+        check_different_constants(('a',), (b'a',))
 
         # check_different_constants() cannot be used because repr(-0j) is
         # '(-0-0j)', but when '(-0-0j)' is evaluated to 0j: we loose the sign.
index dd68006555335d719ccf26cdf5c1f876907fde3e..19d90af152547b2c402512783ba29c4ba60a44b0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: XXXX-XX-XX
 Core and Builtins
 -----------------
 
+- Issue #29337: Fixed possible BytesWarning when compare the code objects.
+  Warnings could be emitted at compile time.
+
 Library
 -------
 
index c334626517613fe44ae6f8dcfadae93c17afd83d..2f1bef2cd1c18614c877bef8204c52acc64bf587 100644 (file)
@@ -521,7 +521,7 @@ _PyCode_ConstantKey(PyObject *op)
             PyTuple_SET_ITEM(tuple, i, item_key);
         }
 
-        key = PyTuple_Pack(3, Py_TYPE(op), op, tuple);
+        key = PyTuple_Pack(2, tuple, op);
         Py_DECREF(tuple);
     }
     else if (PyFrozenSet_CheckExact(op)) {
@@ -555,7 +555,7 @@ _PyCode_ConstantKey(PyObject *op)
         if (set == NULL)
             return NULL;
 
-        key = PyTuple_Pack(3, Py_TYPE(op), op, set);
+        key = PyTuple_Pack(2, set, op);
         Py_DECREF(set);
         return key;
     }
@@ -566,7 +566,7 @@ _PyCode_ConstantKey(PyObject *op)
         if (obj_id == NULL)
             return NULL;
 
-        key = PyTuple_Pack(3, Py_TYPE(op), op, obj_id);
+        key = PyTuple_Pack(2, obj_id, op);
         Py_DECREF(obj_id);
     }
     return key;