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:
parent
228828459c
commit
3e3d77fdaf
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user