What is the goal of “or not” in this code?

I was looking through the library code pyparsing. There I found the following snippet:

    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 weld this a little more, my understanding resultin it is:

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

Here is what I don’t understand: why there or None?

If the first character is invalid, no or Noneget False. If this is correct, but regexp fails, we will get Nonefrom a failed match.

In any case (with False or with None) it if not resultwill do the right thing.

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

+4
source share
1 answer

result None . or None, , result False - .

+3

Source: https://habr.com/ru/post/1682236/


All Articles