[Python-checkins] cpython (merge 3.6 -> default): Merge 3.6

victor.stinner python-checkins at python.org
Tue Nov 22 09:32:50 EST 2016


https://hg.python.org/cpython/rev/09e2c4197dbf
changeset:   105337:09e2c4197dbf
parent:      105334:19adf22d6a5b
parent:      105336:c2cb70c97163
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Nov 22 15:30:53 2016 +0100
summary:
  Merge 3.6

files:
  Lib/test/test_re.py |  4 ++++
  Modules/_sre.c      |  8 +++++++-
  2 files changed, 11 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1781,6 +1781,10 @@
     def test_pattern_compare(self):
         pattern1 = re.compile('abc', re.IGNORECASE)
 
+        # equal to itself
+        self.assertEqual(pattern1, pattern1)
+        self.assertFalse(pattern1 != pattern1)
+
         # equal
         re.purge()
         pattern2 = re.compile('abc', re.IGNORECASE)
diff --git a/Modules/_sre.c b/Modules/_sre.c
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -2683,12 +2683,18 @@
     if (Py_TYPE(lefto) != &Pattern_Type || Py_TYPE(righto) != &Pattern_Type) {
         Py_RETURN_NOTIMPLEMENTED;
     }
+
+    if (lefto == righto) {
+        /* a pattern is equal to itself */
+        return PyBool_FromLong(op == Py_EQ);
+    }
+
     left = (PatternObject *)lefto;
     right = (PatternObject *)righto;
 
     cmp = (left->flags == right->flags
            && left->isbytes == right->isbytes
-           && left->codesize && right->codesize);
+           && left->codesize == right->codesize);
     if (cmp) {
         /* Compare the code and the pattern because the same pattern can
            produce different codes depending on the locale used to compile the

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list