Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4102d25

Browse files
Issue #29337: Fixed possible BytesWarning when compare the code objects.
Warnings could be emitted at compile time.
2 parents 574ff06 + 713640c commit 4102d25

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lib/test/test_compile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ def check_different_constants(const1, const2):
637637
f1 = ns['f1']
638638
f2 = ns['f2']
639639
self.assertIsNot(f1.__code__, f2.__code__)
640+
self.assertNotEqual(f1.__code__, f2.__code__)
640641
self.check_constant(f1, const1)
641642
self.check_constant(f2, const2)
642643
self.assertEqual(repr(f1()), repr(const1))
@@ -645,6 +646,8 @@ def check_different_constants(const1, const2):
645646
check_different_constants(0, 0.0)
646647
check_different_constants(+0.0, -0.0)
647648
check_different_constants((0,), (0.0,))
649+
check_different_constants('a', b'a')
650+
check_different_constants(('a',), (b'a',))
648651

649652
# check_different_constants() cannot be used because repr(-0j) is
650653
# '(-0-0j)', but when '(-0-0j)' is evaluated to 0j: we loose the sign.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.1 release candidate 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #29337: Fixed possible BytesWarning when compare the code objects.
14+
Warnings could be emitted at compile time.
15+
1316
- Issue #29327: Fixed a crash when pass the iterable keyword argument to
1417
sorted().
1518

Objects/codeobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ _PyCode_ConstantKey(PyObject *op)
545545
PyTuple_SET_ITEM(tuple, i, item_key);
546546
}
547547

548-
key = PyTuple_Pack(3, Py_TYPE(op), op, tuple);
548+
key = PyTuple_Pack(2, tuple, op);
549549
Py_DECREF(tuple);
550550
}
551551
else if (PyFrozenSet_CheckExact(op)) {
@@ -579,7 +579,7 @@ _PyCode_ConstantKey(PyObject *op)
579579
if (set == NULL)
580580
return NULL;
581581

582-
key = PyTuple_Pack(3, Py_TYPE(op), op, set);
582+
key = PyTuple_Pack(2, set, op);
583583
Py_DECREF(set);
584584
return key;
585585
}
@@ -590,7 +590,7 @@ _PyCode_ConstantKey(PyObject *op)
590590
if (obj_id == NULL)
591591
return NULL;
592592

593-
key = PyTuple_Pack(3, Py_TYPE(op), op, obj_id);
593+
key = PyTuple_Pack(2, obj_id, op);
594594
Py_DECREF(obj_id);
595595
}
596596
return key;

0 commit comments

Comments
 (0)