mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-07 07:24: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
|
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 a new issue