What is the purpose of `or None` in this code?

Viewed 73

I've been browsing the code of pyparsing library. In there, I found the following fragment:

    result = instring[loc] == self.firstQuoteChar and self.re.match(instring,loc) or None
    if not result:
        raise ParseException(instring, loc, self.errmsg, self)

    loc = result.end()
    ret = result.group()

To boil this down some more, my understanding of the result in there is:

result = firstCharacterIsCorrect(...) and self.re.match(...) or None

Here is what I don't understand: why have or None in there?

If first character is not correct, without or None we get False. If it is correct, but the regexp fails we get None from failed match anyway.

In either case (with False or with None) if not result will do the right thing.

So why add or None? What am I missing? Why is None preferable to False?

1 Answers
Related