Skip to content

Commit

Permalink
[python] fix methodFullName for methods named ^(import).* (#4973)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierpinho authored Sep 27, 2024
1 parent da64780 commit 8b6992d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1638,4 +1638,28 @@ class TypeRecoveryPassTests extends PySrc2CpgFixture(withOssDataflow = false) {
}
}
}

"external method named `import_table`" should {
val cpg = code("""
|import boto3
|client = boto3.client("s3")
|response = client.import_table()
|""".stripMargin)

"have correct methodFullName for `import_table" in {
cpg.call("import_table").l match {
case List(importTable) =>
importTable.methodFullName shouldBe "boto3.py:<module>.client.<returnValue>.import_table"
case result => fail(s"Expected single call to import_table, but got $result")
}
}

"provide meaningful typeFullName for `response`" in {
cpg.assignment.target.isIdentifier.name("response").l match {
case List(response) =>
response.typeFullName shouldBe "boto3.py:<module>.client.<returnValue>.import_table.<returnValue>"
case result => fail(s"Expected single assignment to response, but got $result")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.shiftleft.semanticcpg.language.*

class PythonTypeHintCallLinker(cpg: Cpg) extends XTypeHintCallLinker(cpg) {

override def calls: Iterator[Call] = super.calls.nameNot("^(import).*")
override def calls: Iterator[Call] = super.calls.whereNot(_.isImport)

override def calleeNames(c: Call): Seq[String] = super.calleeNames(c).map {
// Python call from a type
Expand Down

0 comments on commit 8b6992d

Please sign in to comment.