diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-04-19 05:28:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 05:28:04 (GMT) |
commit | b7e1eff8436f6e0c4aac440036092fcf96f82960 (patch) | |
tree | 00c634897d754dae08e0252cdc936fa093bab3c2 /Objects/codeobject.c | |
parent | 9009f3e389123c5f94d4d12f1f51b0a88531c37c (diff) | |
download | cpython-b7e1eff8436f6e0c4aac440036092fcf96f82960.zip cpython-b7e1eff8436f6e0c4aac440036092fcf96f82960.tar.gz cpython-b7e1eff8436f6e0c4aac440036092fcf96f82960.tar.bz2 |
bpo-33299: Return an object itself for some types in _PyCode_ConstantKey(). (GH-6513)
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r-- | Objects/codeobject.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 0509b8e..aa373a0 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -488,14 +488,21 @@ _PyCode_ConstantKey(PyObject *op) { PyObject *key; - /* Py_None and Py_Ellipsis are singleton */ + /* Py_None and Py_Ellipsis are singletons. */ if (op == Py_None || op == Py_Ellipsis || PyLong_CheckExact(op) - || PyBool_Check(op) - || PyBytes_CheckExact(op) || PyUnicode_CheckExact(op) /* code_richcompare() uses _PyCode_ConstantKey() internally */ - || PyCode_Check(op)) { + || PyCode_Check(op)) + { + /* Objects of these types are always different from object of other + * type and from tuples. */ + Py_INCREF(op); + key = op; + } + else if (PyBool_Check(op) || PyBytes_CheckExact(op)) { + /* Make booleans different from integers 0 and 1. + * Avoid BytesWarning from comparing bytes with strings. */ key = PyTuple_Pack(2, Py_TYPE(op), op); } else if (PyFloat_CheckExact(op)) { |