Skip to content

Commit 9ee5d18

Browse files
SONARPY-906 S5864: Fix FP when calling coroutines (#1067)
1 parent fbb290b commit 9ee5d18

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

python-checks/src/main/java/org/sonar/python/checks/ConfusingTypeCheckingCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static class NonCallableCalledCheck extends NonCallableCalled {
6363

6464
@Override
6565
public boolean isNonCallableType(InferredType type) {
66-
return containsDeclaredType(type) && !type.declaresMember("__call__");
66+
return containsDeclaredType(type) && !type.declaresMember("__call__") && !type.mustBeOrExtend("typing.Coroutine");
6767
}
6868

6969
@Override

python-checks/src/test/resources/checks/confusingTypeChecking/nonCallableCalled.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Set, FrozenSet, Union
1+
from typing import Set, FrozenSet, Union, Coroutine
2+
import asyncio
23

34
def empty_union(x: Union['A', 'B']):
45
x()
@@ -29,3 +30,10 @@ def __call__(self, *args, **kwargs): ...
2930
def with_isinstance(x: Base):
3031
if isinstance(x, CallableBase):
3132
x()
33+
34+
35+
async def bar(func: Coroutine):
36+
func() # it's technically possible to call a Coroutine, although it won't behave as a normal function
37+
await asyncio.gather(
38+
func()
39+
)

0 commit comments

Comments
 (0)