Skip to content

Commit 067cbd0

Browse files
Issue python#29337: Fixed possible BytesWarning when compare the code objects.
Warnings could be emitted at compile time.
2 parents c3858bd + 4102d25 commit 067cbd0

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
@@ -630,6 +630,7 @@ def check_different_constants(const1, const2):
630630
f1 = ns['f1']
631631
f2 = ns['f2']
632632
self.assertIsNot(f1.__code__, f2.__code__)
633+
self.assertNotEqual(f1.__code__, f2.__code__)
633634
self.check_constant(f1, const1)
634635
self.check_constant(f2, const2)
635636
self.assertEqual(repr(f1()), repr(const1))
@@ -638,6 +639,8 @@ def check_different_constants(const1, const2):
638639
check_different_constants(0, 0.0)
639640
check_different_constants(+0.0, -0.0)
640641
check_different_constants((0,), (0.0,))
642+
check_different_constants('a', b'a')
643+
check_different_constants(('a',), (b'a',))
641644

642645
# check_different_constants() cannot be used because repr(-0j) is
643646
# '(-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.7.0 alpha 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
@@ -550,7 +550,7 @@ _PyCode_ConstantKey(PyObject *op)
550550
PyTuple_SET_ITEM(tuple, i, item_key);
551551
}
552552

553-
key = PyTuple_Pack(3, Py_TYPE(op), op, tuple);
553+
key = PyTuple_Pack(2, tuple, op);
554554
Py_DECREF(tuple);
555555
}
556556
else if (PyFrozenSet_CheckExact(op)) {
@@ -584,7 +584,7 @@ _PyCode_ConstantKey(PyObject *op)
584584
if (set == NULL)
585585
return NULL;
586586

587-
key = PyTuple_Pack(3, Py_TYPE(op), op, set);
587+
key = PyTuple_Pack(2, set, op);
588588
Py_DECREF(set);
589589
return key;
590590
}
@@ -595,7 +595,7 @@ _PyCode_ConstantKey(PyObject *op)
595595
if (obj_id == NULL)
596596
return NULL;
597597

598-
key = PyTuple_Pack(3, Py_TYPE(op), op, obj_id);
598+
key = PyTuple_Pack(2, obj_id, op);
599599
Py_DECREF(obj_id);
600600
}
601601
return key;

0 commit comments

Comments
 (0)