Skip to content

Commit 3e3d77f

Browse files
committed
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.
1 parent 2288284 commit 3e3d77f

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

pyrogram/filters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ async def __call__(self, client: "pyrogram.Client", update: Update):
7070
client, update
7171
)
7272

73+
# short circuit
74+
if not x:
75+
return False
76+
7377
if inspect.iscoroutinefunction(self.other.__call__):
7478
y = await self.other(client, update)
7579
else:
@@ -97,6 +101,10 @@ async def __call__(self, client: "pyrogram.Client", update: Update):
97101
client, update
98102
)
99103

104+
# short circuit
105+
if x:
106+
return True
107+
100108
if inspect.iscoroutinefunction(self.other.__call__):
101109
y = await self.other(client, update)
102110
else:

0 commit comments

Comments
 (0)