I came across the term "protocol-driven circuit breaking operator" in PEP 532, and couldn't find what exactly it means.
Can you explain what this phrase means?
I came across the term "protocol-driven circuit breaking operator" in PEP 532, and couldn't find what exactly it means.
Can you explain what this phrase means?
In this context, a "protocol" is an API. And "circuit breaking" might be more easily understood by another phrase, "short circuiting." As in:
if text is None or not text.startswith("lorem"):
raise RuntimeError("text should exist and start with 'lorem'")
Since text.startswith()
is only valid code if text
is not None
, the above code "short circuits" using the or
operator, which does not bother to evaluate the right hand argument if the left-hand is true. Similarly, the and
operator short-circuits if the left-hand is false (because the result then must be false).
So the point of this PEP is to enhance the facilities for building expressions which can short-circuit in more elaborate ways.