[issue28727] Implement comparison (x==y and x!=y) for _sre.SRE_Pattern

STINNER Victor report at bugs.python.org
Fri Nov 18 04:15:16 EST 2016


STINNER Victor added the comment:

Serhiy: "There is a problem with locale-depending flags. The same pattern may be compiled with the LOCALE flag to different pattern objects in different locales."

Oh, I didn't know and you are right.

"Perhaps we should compare the compiled code instead of pattern strings. Or both."

PatternObject contains many fields. I used the following two fields which come from re.compile():

* pattern
* flags

I considered that they were enough because pattern_repr() only displays these ones. Other fields:

* groups
* groupindex
* indexgroup
* weakreflist
* isbytes
* codesize, code

weakreflist can be skipped, isbytes is already tested in my patch.

Would it be possible to only compare code instead of pattern? What are groups, groupindex and indexgroup: should we also compare them?

Maybe I can start from  pattern_compare-4.patch and only add a test comparing code?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28727>
_______________________________________


More information about the Python-bugs-list mailing list