Implement short-circuit evaluation for filters

AND and OR operations will not evaluate the second operand
in case the first one is, respectively, False and True.
This commit is contained in:
Dan 2020-08-24 09:20:10 +02:00
parent 228828459c
commit 3e3d77fdaf

View File

@ -70,6 +70,10 @@ class AndFilter(Filter):
client, update
)
# short circuit
if not x:
return False
if inspect.iscoroutinefunction(self.other.__call__):
y = await self.other(client, update)
else:
@ -97,6 +101,10 @@ class OrFilter(Filter):
client, update
)
# short circuit
if x:
return True
if inspect.iscoroutinefunction(self.other.__call__):
y = await self.other(client, update)
else: