mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 20:14:51 +00:00
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
1 changed files with 8 additions and 0 deletions
|
|
@ -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 a new issue