Skip to content

Commit

Permalink
Support for python interface files
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 7, 2024
1 parent b343372 commit 55f8b71
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,8 @@ interface Python {
val context_expr: ASTBASEexpr by lazy { "context_expr" of pyObject }
val optional_vars: ASTBASEexpr? by lazy { "optional_vars" of pyObject }
}

class Ellipsis(python: PyObject) : AST(python)
}

private inline infix fun <reified T> String.of(pyObject: PyObject): T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import org.neo4j.ogm.annotation.Transient
/** The Python language. */
class PythonLanguage :
Language<PythonLanguageFrontend>(), HasShortCircuitOperators, HasOperatorOverloading {
override val fileExtensions = listOf("py")
override val fileExtensions = listOf("py", "pyi")
override val namespaceDelimiter = "."
@Transient
override val frontend: KClass<out PythonLanguageFrontend> = PythonLanguageFrontend::class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ fun fromPython(pyObject: Any?): Python.AST {

// complex numbers
"complex" -> TODO("Complex numbers are not supported yet")
"ellipsis" -> Python.Ellipsis(pyObject)
else -> {
TODO("Implement for ${pyObject.getAttr("__class__")}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,22 @@ class PythonFrontendTest : BaseTest() {
assertInvokes(call, cCompletelyDifferentFunc)
}

@Test
fun testInterfaceStubs() {
val topLevel = Path.of("src", "test", "resources", "python")
val result =
analyze(
listOf(
topLevel.resolve("pyi/io.pyi").toFile(),
),
topLevel,
true
) {
it.registerLanguage<PythonLanguage>()
}
assertNotNull(result)
}

class PythonValueEvaluator : ValueEvaluator() {
override fun computeBinaryOpEffect(
lhsValue: Any?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import de.fraunhofer.aisec.cpg.graph.edge.Properties
import de.fraunhofer.aisec.cpg.test.analyze
import java.nio.file.Path
import kotlin.test.Test
<<<<<<< HEAD
import kotlin.test.assertContains
=======
>>>>>>> 291759a3bb (Supporting `posonlyargs` in Python)
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

Expand Down

0 comments on commit 55f8b71

Please sign in to comment.