Skip to content

Commit

Permalink
Added := as simple operator in Python (#1785)
Browse files Browse the repository at this point in the history
Named expressions in Python use `:=` as operator. Therefore we need to include it in the language definition. Otherwise, the `access` value of a reference will not be set correctly.
  • Loading branch information
oxisto authored Oct 8, 2024
1 parent 467013f commit 3e2db5c
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import de.fraunhofer.aisec.cpg.graph.autoType
import de.fraunhofer.aisec.cpg.graph.declarations.ParameterDeclaration
import de.fraunhofer.aisec.cpg.graph.scopes.Symbol
import de.fraunhofer.aisec.cpg.graph.statements.expressions.BinaryOperator
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Reference
import de.fraunhofer.aisec.cpg.graph.statements.expressions.UnaryOperator
import de.fraunhofer.aisec.cpg.graph.types.*
import kotlin.reflect.KClass
Expand All @@ -49,6 +50,14 @@ class PythonLanguage :
override val conjunctiveOperators = listOf("and")
override val disjunctiveOperators = listOf("or")

/**
* You can either use `=` or `:=` in Python. But the latter is only available in a "named
* expression" (`a = (x := 1)`). We still need to include both however, otherwise
* [Reference.access] will not be set correctly in "named expressions".
*/
override val simpleAssignmentOperators: Set<String>
get() = setOf("=", ":=")

/**
* All operators which perform and assignment and an operation using lhs and rhs. See
* https://docs.python.org/3/library/operator.html#in-place-operators
Expand Down

0 comments on commit 3e2db5c

Please sign in to comment.