File tree Expand file tree Collapse file tree
main/java/org/sonar/python/checks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717package org .sonar .python .checks ;
1818
1919import javax .annotation .Nullable ;
20+
2021import org .sonar .check .Rule ;
2122import org .sonar .plugins .python .api .PythonSubscriptionCheck ;
2223import org .sonar .plugins .python .api .SubscriptionContext ;
2324import org .sonar .plugins .python .api .tree .AwaitExpression ;
2425import org .sonar .plugins .python .api .tree .BaseTreeVisitor ;
26+ import org .sonar .plugins .python .api .tree .ComprehensionFor ;
2527import org .sonar .plugins .python .api .tree .ForStatement ;
2628import org .sonar .plugins .python .api .tree .FunctionDef ;
2729import org .sonar .plugins .python .api .tree .ReturnStatement ;
@@ -150,6 +152,12 @@ public void visitFunctionDef(FunctionDef functionDef) {
150152 // Skip nested functions
151153 }
152154
155+ @ Override
156+ public void visitComprehensionFor (ComprehensionFor tree ) {
157+ asyncFeatureFound |= tree .asyncToken () != null ;
158+ super .visitComprehensionFor (tree );
159+ }
160+
153161 @ Override
154162 protected void scan (@ Nullable Tree tree ) {
155163 // Stop scanning if we've already found an async feature
Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ async def __anext__(self):
142142class AsyncResource :
143143 async def __aclose__ (self ):
144144 print ("Releasing resources" )
145-
145+
146146class AsyncAwaitableObject :
147147 async def __await__ (self ):
148148 yield "something"
@@ -183,3 +183,9 @@ class MyOtherClass(MyClass):
183183 async def my_method (self ):
184184 # No issue on overriding methods
185185 do_something ()
186+
187+ async def async_comprehension ():
188+ return [something async for something in async_iterable ()]
189+
190+ async def sync_comprehension (): # Noncompliant
191+ return [something for something in async_iterable ()]
You can’t perform that action at this time.
0 commit comments