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
|
client, update
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# short circuit
|
||||||
|
if not x:
|
||||||
|
return False
|
||||||
|
|
||||||
if inspect.iscoroutinefunction(self.other.__call__):
|
if inspect.iscoroutinefunction(self.other.__call__):
|
||||||
y = await self.other(client, update)
|
y = await self.other(client, update)
|
||||||
else:
|
else:
|
||||||
@ -97,6 +101,10 @@ class OrFilter(Filter):
|
|||||||
client, update
|
client, update
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# short circuit
|
||||||
|
if x:
|
||||||
|
return True
|
||||||
|
|
||||||
if inspect.iscoroutinefunction(self.other.__call__):
|
if inspect.iscoroutinefunction(self.other.__call__):
|
||||||
y = await self.other(client, update)
|
y = await self.other(client, update)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user