Skip to content

Commit c426597

Browse files
committed
containing classIds for PythonTree; some fixes
1 parent 13edb82 commit c426597

5 files changed

Lines changed: 35 additions & 12 deletions

File tree

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,13 @@ sealed class PythonModel(classId: PythonClassId): UtModel(classId) {
274274
class PythonTreeModel(
275275
val tree: PythonTree.PythonTreeNode,
276276
classId: PythonClassId,
277-
): PythonModel(classId)
277+
): PythonModel(classId) {
278+
override val allContainingClassIds: Set<PythonClassId>
279+
get() {
280+
val children = tree.children.map { PythonTreeModel(it, it.type) }
281+
return super.allContainingClassIds + children.flatMap { it.allContainingClassIds }
282+
}
283+
}
278284

279285
class PythonDefaultModel(
280286
val repr: String,

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/PythonTree.kt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package org.utbot.framework.plugin.api
33
object PythonTree {
44
open class PythonTreeNode(
55
val type: PythonClassId,
6-
)
6+
) {
7+
open val children: List<PythonTreeNode> = emptyList()
8+
}
79

810
class PrimitiveNode(
911
type: PythonClassId,
@@ -12,19 +14,31 @@ object PythonTree {
1214

1315
class ListNode(
1416
val items: List<PythonTreeNode>
15-
): PythonTreeNode(PythonClassId("builtins.list"))
17+
): PythonTreeNode(PythonClassId("builtins.list")) {
18+
override val children: List<PythonTreeNode>
19+
get() = items
20+
}
1621

1722
class DictNode(
1823
val items: Map<PythonTreeNode, PythonTreeNode>
19-
): PythonTreeNode(PythonClassId("builtins.dict"))
24+
): PythonTreeNode(PythonClassId("builtins.dict")) {
25+
override val children: List<PythonTreeNode>
26+
get() = items.values + items.keys
27+
}
2028

2129
class SetNode(
2230
val items: Set<PythonTreeNode>
23-
): PythonTreeNode(PythonClassId("builtins.set"))
31+
): PythonTreeNode(PythonClassId("builtins.set")) {
32+
override val children: List<PythonTreeNode>
33+
get() = items.toList()
34+
}
2435

2536
class TupleNode(
2637
val items: List<PythonTreeNode>
27-
): PythonTreeNode(PythonClassId("builtins.tuple"))
38+
): PythonTreeNode(PythonClassId("builtins.tuple")) {
39+
override val children: List<PythonTreeNode>
40+
get() = items
41+
}
2842

2943
class ReduceNode(
3044
type: PythonClassId,
@@ -33,5 +47,8 @@ object PythonTree {
3347
val state: Map<String, PythonTreeNode>,
3448
val listitems: List<PythonTreeNode>,
3549
val dictitems: Map<PythonTreeNode, PythonTreeNode>,
36-
): PythonTreeNode(type)
50+
): PythonTreeNode(type) {
51+
override val children: List<PythonTreeNode>
52+
get() = args + state.values + listitems + dictitems.values + dictitems.keys
53+
}
3754
}

utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PythonEngine(
5555

5656
val resultAsModel = PythonTreeModel(
5757
resultJSON.output,
58-
PythonClassId(resultJSON.type)
58+
resultJSON.type
5959
)
6060
val result = UtExecutionSuccess(resultAsModel)
6161

utbot-python/src/main/kotlin/org/utbot/python/PythonEvaluation.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.python
22

3+
import org.utbot.framework.plugin.api.PythonClassId
34
import org.utbot.framework.plugin.api.PythonTree
45
import org.utbot.framework.plugin.api.UtModel
56
import org.utbot.python.code.KlaxonPythonTreeParser
@@ -15,7 +16,7 @@ class EvaluationSuccess(val output: OutputData, val isException: Boolean): Evalu
1516
operator fun component2() = isException
1617
}
1718

18-
data class OutputData(val output: PythonTree.PythonTreeNode, val type: String)
19+
data class OutputData(val output: PythonTree.PythonTreeNode, val type: PythonClassId)
1920

2021
object PythonEvaluation {
2122
fun evaluate(

utbot-python/src/main/resources/python_tree_serializer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import types
32
from itertools import zip_longest
43

@@ -8,9 +7,9 @@ class _PythonTreeSerializer:
87
def get_type(py_object):
98
if py_object is None:
109
return 'types.NoneType'
11-
module = inspect.getmodule(type(py_object))
10+
module = type(py_object).__module__
1211
return '{module}.{name}'.format(
13-
module='' if module is None else module.__name__,
12+
module=module,
1413
name=type(py_object).__name__,
1514
)
1615

0 commit comments

Comments
 (0)