diff options
-rw-r--r-- | Lib/test/test_re.py | 4 | ||||
-rw-r--r-- | Modules/_sre.c | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 4fcd2d4..84131d2 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1781,6 +1781,10 @@ SUBPATTERN None 0 0 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 index 1b77416..979e61f 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2683,6 +2683,12 @@ pattern_richcompare(PyObject *lefto, PyObject *righto, int op) 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; |