Skip to content

Commit 1171031

Browse files
committed
Added pythonTypeRepresentation
1 parent 6416341 commit 1171031

File tree

1 file changed

+14
-7
lines changed
  • utbot-python/src/main/kotlin/org/utbot/python/newtyping

1 file changed

+14
-7
lines changed

utbot-python/src/main/kotlin/org/utbot/python/newtyping/PythonType.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ fun Type.isPythonObjectType(): Boolean {
2929
return description.name.prefix == listOf("builtins") && description.name.name == "object"
3030
}
3131

32+
fun Type.pythonTypeRepresentation(): String {
33+
val description = pythonDescription()
34+
val root = description.name.prefix.joinToString() + "." + description.name.name
35+
val params = pythonAnnotationParameters()
36+
if (params.isEmpty())
37+
return root
38+
return "$root[${params.joinToString { it.pythonTypeRepresentation() }}]"
39+
}
40+
3241
class PythonTypeStorage(
3342
val pythonObject: Type,
3443
val pythonBool: Type,
@@ -74,10 +83,8 @@ sealed class PythonTypeDescription(name: Name) : TypeMetaDataWithName(name) {
7483
open fun getMemberByName(storage: PythonTypeStorage, type: Type, name: String): PythonAttribute? =
7584
// overridden for some types
7685
getNamedMembers(type).find { it.name == name }
77-
78-
open fun createTypeWithNewAnnotationParameters(origin: Type, newParams: List<Type>): Type =
79-
// overriden for Callable
80-
DefaultSubstitutionProvider.substituteAll(origin, newParams)
86+
open fun createTypeWithNewAnnotationParameters(like: Type, newParams: List<Type>): Type = // overriden for Callable
87+
DefaultSubstitutionProvider.substituteAll(like.getOrigin(), newParams)
8188
}
8289

8390
sealed class PythonCompositeTypeDescription(
@@ -204,17 +211,17 @@ class PythonCallableTypeDescription(
204211
Positional
205212
}
206213

207-
override fun createTypeWithNewAnnotationParameters(origin: Type, newParams: List<Type>): Type {
214+
override fun createTypeWithNewAnnotationParameters(like: Type, newParams: List<Type>): Type {
208215
val args = newParams.dropLast(1)
209216
val returnValue = newParams.last()
210217
return createPythonCallableType(
211-
origin.parameters.size,
218+
like.parameters.size,
212219
argumentKinds,
213220
argumentNames,
214221
isClassMethod,
215222
isStaticMethod
216223
) { self ->
217-
val oldToNewParameters = (origin.parameters zip self.parameters).associate {
224+
val oldToNewParameters = (like.parameters zip self.parameters).associate {
218225
(it.first as TypeParameter) to it.second
219226
}
220227
val newArgs = args.map {

0 commit comments

Comments
 (0)