mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Merge pull request #19136 from github/tausbn/python-modernise-mixed-tuple-returns-query
Python: Modernize `py/mixed-tuple-returns`
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* @kind problem
|
||||
* @tags reliability
|
||||
* maintainability
|
||||
* quality
|
||||
* @problem.severity recommendation
|
||||
* @sub-severity high
|
||||
* @precision high
|
||||
@@ -11,13 +12,15 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import semmle.python.ApiGraphs
|
||||
|
||||
predicate returns_tuple_of_size(Function func, int size, AstNode origin) {
|
||||
exists(Return return, TupleValue val |
|
||||
predicate returns_tuple_of_size(Function func, int size, Tuple tuple) {
|
||||
exists(Return return, DataFlow::Node value |
|
||||
value.asExpr() = return.getValue() and
|
||||
return.getScope() = func and
|
||||
return.getValue().pointsTo(val, origin)
|
||||
any(DataFlow::LocalSourceNode n | n.asExpr() = tuple).flowsTo(value)
|
||||
|
|
||||
size = val.length()
|
||||
size = count(int n | exists(tuple.getElt(n)))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -25,6 +28,8 @@ from Function func, int s1, int s2, AstNode t1, AstNode t2
|
||||
where
|
||||
returns_tuple_of_size(func, s1, t1) and
|
||||
returns_tuple_of_size(func, s2, t2) and
|
||||
s1 < s2
|
||||
s1 < s2 and
|
||||
// Don't report on functions that have a return type annotation
|
||||
not exists(func.getDefinition().(FunctionExpr).getReturns())
|
||||
select func, func.getQualifiedName() + " returns $@ and $@.", t1, "tuple of size " + s1, t2,
|
||||
"tuple of size " + s2
|
||||
|
||||
Reference in New Issue
Block a user