Skip to content

Commit

Permalink
Issue python#29337: Fixed possible BytesWarning when compare the code…
Browse files Browse the repository at this point in the history
… objects.

Warnings could be emitted at compile time.
  • Loading branch information
serhiy-storchaka committed Jan 24, 2017
2 parents 574ff06 + 713640c commit 4102d25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ def check_different_constants(const1, const2):
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))
Expand All @@ -645,6 +646,8 @@ def check_different_constants(const1, const2):
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.
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ What's New in Python 3.6.1 release candidate 1?
Core and Builtins
-----------------

- Issue #29337: Fixed possible BytesWarning when compare the code objects.
Warnings could be emitted at compile time.

- Issue #29327: Fixed a crash when pass the iterable keyword argument to
sorted().

Expand Down
6 changes: 3 additions & 3 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,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)) {
Expand Down Expand Up @@ -579,7 +579,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;
}
Expand All @@ -590,7 +590,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;
Expand Down

0 comments on commit 4102d25

Please sign in to comment.