Skip to content

Commit e8b81f6

Browse files
committed
some fixes
1 parent 8aa4860 commit e8b81f6

5 files changed

Lines changed: 39 additions & 37 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ class PythonSetModel(
363363
val stores: Set<PythonModel>
364364
) : PythonModel(classId) {
365365
override fun toString() = withToStringThreadLocalReentrancyGuard {
366-
stores.joinToString(", ", "{", "}") { it.toString() }
366+
if (stores.isEmpty())
367+
"set()"
368+
else
369+
stores.joinToString(", ", "{", "}") { it.toString() }
367370
}
368371

369372
override val allContainingClassIds: Set<PythonClassId>

utbot-python/samples/general.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ def h(x):
4141
return 2
4242

4343

44-
class A:
45-
def __init__(self, val: int):
46-
self.description = val
47-
48-
49-
class B:
50-
def __init__(self, val: complex):
51-
self.description = val
52-
53-
def sqrt(self):
54-
return self.description ** 0.5
55-
56-
5744
def a(x):
5845
x.description += 1
5946
return x.description
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class A:
2+
def __init__(self, val: int):
3+
self.description = val
4+
5+
6+
class B:
7+
def __init__(self, val: complex):
8+
self.description = val
9+
10+
def sqrt(self):
11+
return self.description ** 0.5

utbot-python/src/main/kotlin/org/utbot/python/code/CodeGen.kt

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import io.github.danielnaczo.python3parser.model.expr.operators.binaryops.compar
1414
import io.github.danielnaczo.python3parser.model.mods.Module
1515
import io.github.danielnaczo.python3parser.model.stmts.Body
1616
import io.github.danielnaczo.python3parser.model.stmts.Statement
17+
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.If
1718
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.functionStmts.FunctionDef
1819
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.functionStmts.parameters.Parameter
1920
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.functionStmts.parameters.Parameters
@@ -159,32 +160,25 @@ object PythonCodeGenerator {
159160
listOf(Name("out['output']")),
160161
Atom(Name("repr"), listOf(createArguments(listOf(Name(outputName)))))
161162
),
162-
Assign(
163-
listOf(Name("out['type']")),
164-
Add(
165-
Atom(
166-
Atom(
167-
Name("inspect.getmodule"),
168-
listOf(createArguments(listOf(
163+
If(
164+
Name("$outputName != None"),
165+
Body(listOf(Assign(
166+
listOf(Name("out['type']")),
167+
Add(
168+
Name("type($outputName).__module__"),
169+
Add(
170+
Str("."),
171+
Atom(
169172
Atom(
170173
Name("type"),
171174
listOf(createArguments(listOf(Name(outputName))))
172-
)
173-
)))
174-
),
175-
listOf(Attribute(Identifier("__name__")))
176-
),
177-
Add(
178-
Str("."),
179-
Atom(
180-
Atom(
181-
Name("type"),
182-
listOf(createArguments(listOf(Name(outputName))))
175+
),
176+
listOf(Attribute(Identifier("__name__")))
183177
),
184-
listOf(Attribute(Identifier("__name__")))
185-
),
178+
)
186179
)
187-
)
180+
))),
181+
Body(listOf(Name("out['type'] = 'types.NoneType'")))
188182
),
189183
Atom(
190184
Name("print"),

utbot-python/src/main/kotlin/org/utbot/python/typing/PythonTypeCollector.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.utbot.framework.plugin.api.PythonClassId
1313
import org.utbot.python.code.ClassInfoCollector
1414
import org.utbot.python.code.PythonClass
1515
import org.utbot.python.code.PythonCode
16+
import org.utbot.python.utils.AnnotationNormalizer
1617
import org.utbot.python.utils.AnnotationNormalizer.annotationFromProjectToClassId
1718
import org.utbot.python.utils.AnnotationNormalizer.annotationFromStubToClassId
1819
import java.io.File
@@ -47,7 +48,10 @@ object PythonTypesStorage {
4748
): Set<NormalizedPythonAnnotation> {
4849
val fromStubs = mapToClassId(StubFileFinder.findTypeWithMethod(methodName))
4950
val fromProject = projectClasses.mapNotNull {
50-
if (it.info.methods.contains(methodName)) NormalizedPythonAnnotation(it.pythonClass.name) else null
51+
if (it.info.methods.contains(methodName))
52+
AnnotationNormalizer.pythonClassIdToNormalizedAnnotation(it.name)
53+
else
54+
null
5155
}
5256
return (fromStubs union fromProject).toSet()
5357
}
@@ -57,7 +61,10 @@ object PythonTypesStorage {
5761
): Set<NormalizedPythonAnnotation> {
5862
val fromStubs = mapToClassId(StubFileFinder.findTypeWithField(fieldName))
5963
val fromProject = projectClasses.mapNotNull {
60-
if (it.info.fields.contains(fieldName)) NormalizedPythonAnnotation(it.pythonClass.name) else null
64+
if (it.info.fields.contains(fieldName))
65+
AnnotationNormalizer.pythonClassIdToNormalizedAnnotation(it.name)
66+
else
67+
null
6168
}
6269
return (fromStubs union fromProject).toSet()
6370
}

0 commit comments

Comments
 (0)