You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Restrict usage of coroutines (initialized, but not awaited) as boolean conditions
Thesis
Example:
asyncdefsome_coro() ->bool:
returnTrueifsome_coro(): # The rule should fail at this linepass# Also, it should work with variable declarationsupposed_boolean=some_coro()
ifsupposed_boolean: # The rule should fail at this linepass
If you use class-based awaitable with an overloaded __bool__ method and want to check its actual condition, you can use the following construction:
classMyCoro:
def__await__():
passdef__bool___():
returnTruecoro_condition=bool(MyCoro()) # The rule is passed
Reasoning
This rule aims to prevent common errors that may occur due to overlooking the await keyword before using coroutines in if statements.
linters and type checkers do not consider the usage of coroutines in if statements as an error since any type can be treated as a boolean, leading to subtle bugs.
The text was updated successfully, but these errors were encountered:
Rule request:
Restrict usage of coroutines (initialized, but not awaited) as boolean conditions
Thesis
Example:
If you use class-based awaitable with an overloaded
__bool__
method and want to check its actual condition, you can use the following construction:Reasoning
This rule aims to prevent common errors that may occur due to overlooking the
await
keyword before using coroutines in if statements.linters and type checkers do not consider the usage of coroutines in if statements as an error since any type can be treated as a boolean, leading to subtle bugs.
The text was updated successfully, but these errors were encountered: