Python: more logic adjustment

Not sure why the missing result is missing. There is
and edge with label `getAwaited` from `pkg.async_func` on line 22
to `coro` on line 23.
This commit is contained in:
Rasmus Lerchedahl Petersen
2021-10-26 10:57:27 +02:00
parent f91e43c068
commit 8a81d42e6f
3 changed files with 15 additions and 15 deletions

View File

@@ -494,26 +494,26 @@ module API {
// - `awaitedValue` is `x`
// - `result` is `await x`
exists(Await await |
result.asExpr() = await and
await.getValue() = awaitedValue.asExpr()
await.getValue() = awaitedValue.asExpr() and
result.asExpr() = await
)
or
// `async for x in l`
// - `awaitedValue` is `l`
// - `result` is `l` (should perhaps be `x`, but that should really be a read)
// - `result` is `l` (`x` is behind a read step)
exists(AsyncFor asyncFor |
result.asExpr() = asyncFor.getIter() and
// To consider `x` the result of awaiting, we would use asyncFor.getTarget() = awaitedValue.asExpr(),
// but that is behind a read step rather than a flow step.
asyncFor.getIter() = awaitedValue.asExpr()
asyncFor.getIter() = awaitedValue.asExpr() and
result.asExpr() = asyncFor.getIter()
)
or
// `async with x as y`
// - `awaitedValue` is `x`
// - `result` is `x` and `y` if it exists
exists(AsyncWith asyncWith |
result.asExpr() = asyncWith.getContextExpr() and
awaitedValue.asExpr() in [
awaitedValue.asExpr() = asyncWith.getContextExpr() and
result.asExpr() in [
// `x`
asyncWith.getContextExpr(),
// `y`, if it exists

View File

@@ -75,26 +75,26 @@ private module Asyncpg {
// - `awaitedValue` is `x`
// - `result` is `await x`
exists(Await await |
result.asExpr() = await and
await.getValue() = awaitedValue.asExpr()
await.getValue() = awaitedValue.asExpr() and
result.asExpr() = await
)
or
// `async for x in l`
// - `awaitedValue` is local source of `l`
// - `result` is `l`
exists(AsyncFor asyncFor, DataFlow::Node awaited |
result.asExpr() = asyncFor.getIter() and
asyncFor.getIter() = awaited.asExpr() and
awaited.getALocalSource() = awaitedValue
awaited.getALocalSource() = awaitedValue and
result.asExpr() = asyncFor.getIter()
)
or
// `async with x as y`
// - `awaitedValue` is local source of `x`
// - `result` is `x` and `y`
exists(AsyncWith asyncWith, DataFlow::Node awaited |
result.asExpr() = asyncWith.getContextExpr() and
awaited.asExpr() in [asyncWith.getContextExpr(), asyncWith.getOptionalVars()] and
awaited.getALocalSource() = awaitedValue
awaited.asExpr() = asyncWith.getContextExpr() and
awaited.getALocalSource() = awaitedValue and
result.asExpr() in [asyncWith.getContextExpr(), asyncWith.getOptionalVars()]
)
}

View File

@@ -12,7 +12,7 @@ async def bar():
return result # $ use=moduleImport("pkg").getMember("async_func").getReturn().getAwaited() awaited=moduleImport("pkg").getMember("async_func").getReturn()
async def test_async_with():
async with pkg.async_func() as result: # $ use=moduleImport("pkg").getMember("async_func").getReturn() awaited=moduleImport("pkg").getMember("async_func").getReturn()
async with pkg.async_func() as result: # $ use=moduleImport("pkg").getMember("async_func").getReturn().getAwaited() awaited=moduleImport("pkg").getMember("async_func").getReturn()
return result # $ use=moduleImport("pkg").getMember("async_func").getReturn() awaited=moduleImport("pkg").getMember("async_func").getReturn()
async def test_async_for():