diff options
author | stratakis <cstratak@redhat.com> | 2017-11-02 10:32:54 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-11-02 10:32:54 (GMT) |
commit | e8b19656396381407ad91473af5da8b0d4346e88 (patch) | |
tree | 16638970d5014728a49808d0c80c4af0fe6ccb91 /Modules/_datetimemodule.c | |
parent | 4f469c096628af730b17798d0ebfd8925bfde836 (diff) | |
download | cpython-e8b19656396381407ad91473af5da8b0d4346e88.zip cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.gz cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.bz2 |
bpo-23699: Use a macro to reduce boilerplate code in rich comparison functions (GH-793)
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r-- | Modules/_datetimemodule.c | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 09b5579..b50cdda 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1442,22 +1442,7 @@ build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag) static PyObject * diff_to_bool(int diff, int op) { - PyObject *result; - int istrue; - - switch (op) { - case Py_EQ: istrue = diff == 0; break; - case Py_NE: istrue = diff != 0; break; - case Py_LE: istrue = diff <= 0; break; - case Py_GE: istrue = diff >= 0; break; - case Py_LT: istrue = diff < 0; break; - case Py_GT: istrue = diff > 0; break; - default: - Py_UNREACHABLE(); - } - result = istrue ? Py_True : Py_False; - Py_INCREF(result); - return result; + Py_RETURN_RICHCOMPARE(diff, 0, op); } /* Raises a "can't compare" TypeError and returns NULL. */ |