Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b87b69

Browse files
committed
Merge 3.6
2 parents 9ad8a63 + bcf4dcc commit 0b87b69

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/test/test_re.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,10 @@ def test_enum(self):
17811781
def test_pattern_compare(self):
17821782
pattern1 = re.compile('abc', re.IGNORECASE)
17831783

1784+
# equal to itself
1785+
self.assertEqual(pattern1, pattern1)
1786+
self.assertFalse(pattern1 != pattern1)
1787+
17841788
# equal
17851789
re.purge()
17861790
pattern2 = re.compile('abc', re.IGNORECASE)

Modules/_sre.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,12 +2683,18 @@ pattern_richcompare(PyObject *lefto, PyObject *righto, int op)
26832683
if (Py_TYPE(lefto) != &Pattern_Type || Py_TYPE(righto) != &Pattern_Type) {
26842684
Py_RETURN_NOTIMPLEMENTED;
26852685
}
2686+
2687+
if (lefto == righto) {
2688+
/* a pattern is equal to itself */
2689+
return PyBool_FromLong(op == Py_EQ);
2690+
}
2691+
26862692
left = (PatternObject *)lefto;
26872693
right = (PatternObject *)righto;
26882694

26892695
cmp = (left->flags == right->flags
26902696
&& left->isbytes == right->isbytes
2691-
&& left->codesize && right->codesize);
2697+
&& left->codesize == right->codesize);
26922698
if (cmp) {
26932699
/* Compare the code and the pattern because the same pattern can
26942700
produce different codes depending on the locale used to compile the

0 commit comments

Comments
 (0)