[New-bugs-announce] [issue1208] Match object should be guaranteed to always be true

Martin Horcicka report at bugs.python.org
Wed Sep 26 22:34:54 CEST 2007

New submission from Martin Horcicka:

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.

components: Documentation, Library (Lib)
messages: 56149
nosy: horcicka
severity: normal
status: open
title: Match object should be guaranteed to always be true
type: behavior

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list