Issue 1208: Match object should be guaranteed to always be true (original) (raw)

Many people expect the match object from the re module to always be true. They use it this way:

if regexp.match(string): do_something()

Some people do not expect it and use it differently:

if regexp.match(string) is not None: do_something()

Even in the standard library both ways are used. The first way is simpler and nicer and thus better, in my opinion.

Current implementation of the match object (implemented as _sre.SRE_Match object in Modules/_sre.c) seems to guarantee the trueness (someone should check it) but in fact, there is no guarantee described in the documentation.