@@ -5,15 +5,15 @@ import org.utbot.python.newtyping.general.Name
5
5
import org.utbot.python.newtyping.utils.isRequired
6
6
7
7
sealed class PythonTypeDescription (name : Name ) : TypeMetaDataWithName(name) {
8
- open fun castToCompatibleTypeApi (type : Type ): Type = type
9
- open fun getNamedMembers (type : Type ): List <PythonDefinition > = emptyList() // direct members (without inheritance)
10
- open fun getAnnotationParameters (type : Type ): List <Type > = emptyList()
11
- open fun getMemberByName (storage : PythonTypeStorage , type : Type , name : String ): PythonDefinition ? =
8
+ open fun castToCompatibleTypeApi (type : UtType ): UtType = type
9
+ open fun getNamedMembers (type : UtType ): List <PythonDefinition > = emptyList() // direct members (without inheritance)
10
+ open fun getAnnotationParameters (type : UtType ): List <UtType > = emptyList()
11
+ open fun getMemberByName (storage : PythonTypeHintsStorage , type : UtType , name : String ): PythonDefinition ? =
12
12
// overridden for some types
13
13
getNamedMembers(type).find { it.meta.name == name }
14
- open fun createTypeWithNewAnnotationParameters (like : Type , newParams : List <Type >): Type = // overriden for Callable
14
+ open fun createTypeWithNewAnnotationParameters (like : UtType , newParams : List <UtType >): UtType = // overriden for Callable
15
15
DefaultSubstitutionProvider .substituteAll(like.getOrigin(), newParams)
16
- open fun getTypeRepresentation (type : Type ): String { // overriden for Callable
16
+ open fun getTypeRepresentation (type : UtType ): String { // overriden for Callable
17
17
if (name.prefix == listOf (" builtins" ) && name.name == " tuple" ) {
18
18
return " ${getTypeName()} [${type.parameters.first().pythonTypeRepresentation()} , ...]"
19
19
}
@@ -35,7 +35,7 @@ sealed class PythonTypeDescription(name: Name) : TypeMetaDataWithName(name) {
35
35
fun getName (): String {
36
36
return name.name
37
37
}
38
- fun getModules (type : Type ): Set <String > {
38
+ fun getModules (type : UtType ): Set <String > {
39
39
val cur = if (name.prefix.isNotEmpty())
40
40
setOf (name.prefix.joinToString(separator = " ." ))
41
41
else
@@ -50,12 +50,12 @@ sealed class PythonCompositeTypeDescription(
50
50
name : Name ,
51
51
private val memberDescriptions : List <PythonDefinitionDescription >
52
52
): PythonTypeDescription(name) {
53
- override fun castToCompatibleTypeApi (type : Type ): CompositeType {
53
+ override fun castToCompatibleTypeApi (type : UtType ): CompositeType {
54
54
return type as ? CompositeType
55
55
? : error(" Got unexpected type PythonCompositeTypeDescription: $type " )
56
56
}
57
57
58
- override fun getNamedMembers (type : Type ): List <PythonDefinition > {
58
+ override fun getNamedMembers (type : UtType ): List <PythonDefinition > {
59
59
val compositeType = castToCompatibleTypeApi(type)
60
60
assert (compositeType.members.size == memberDescriptions.size)
61
61
return (memberDescriptions zip compositeType.members).map { (descr, typ) ->
@@ -66,8 +66,8 @@ sealed class PythonCompositeTypeDescription(
66
66
}
67
67
}
68
68
69
- override fun getAnnotationParameters (type : Type ): List <Type > = type.parameters
70
- fun mro (storage : PythonTypeStorage , type : Type ): List <Type > {
69
+ override fun getAnnotationParameters (type : UtType ): List <UtType > = type.parameters
70
+ fun mro (storage : PythonTypeHintsStorage , type : UtType ): List <UtType > {
71
71
val compositeType = castToCompatibleTypeApi(type)
72
72
var bases = compositeType.supertypes
73
73
if (bases.isEmpty() && ! type.isPythonObjectType())
@@ -82,7 +82,7 @@ sealed class PythonCompositeTypeDescription(
82
82
linBases.removeIf { it.isEmpty() }
83
83
if (linBases.isEmpty())
84
84
break
85
- lateinit var addAtThisIteration: Type
85
+ lateinit var addAtThisIteration: UtType
86
86
for (seq in linBases) {
87
87
val head = seq.first()
88
88
val isContainedSomewhereElse = linBases.any {
@@ -102,7 +102,7 @@ sealed class PythonCompositeTypeDescription(
102
102
return result
103
103
}
104
104
105
- override fun getMemberByName (storage : PythonTypeStorage , type : Type , name : String ): PythonDefinition ? {
105
+ override fun getMemberByName (storage : PythonTypeHintsStorage , type : UtType , name : String ): PythonDefinition ? {
106
106
for (parent in mro(storage, type)) {
107
107
val cur = parent.getPythonAttributes().find { it.meta.name == name }
108
108
if (cur != null )
@@ -119,7 +119,7 @@ class PythonTypeVarDescription(
119
119
val variance : Variance ,
120
120
val parameterKind : ParameterKind
121
121
) : PythonTypeDescription(name) {
122
- override fun castToCompatibleTypeApi (type : Type ): TypeParameter {
122
+ override fun castToCompatibleTypeApi (type : UtType ): TypeParameter {
123
123
return type as ? TypeParameter
124
124
? : error(" Got unexpected type PythonTypeVarDescription: $type " )
125
125
}
@@ -154,17 +154,17 @@ class PythonCallableTypeDescription(
154
154
val argumentNames : List <String ?> // like in mypy's CallableType: https://github.com/python/mypy/blob/master/mypy/types.py#L1672
155
155
): PythonTypeDescription(pythonCallableName) {
156
156
val numberOfArguments = argumentKinds.size
157
- override fun castToCompatibleTypeApi (type : Type ): FunctionType {
157
+ override fun castToCompatibleTypeApi (type : UtType ): FunctionType {
158
158
return type as ? FunctionType
159
159
? : error(" Got unexpected type PythonCallableTypeDescription: $type " )
160
160
}
161
161
162
- override fun getNamedMembers (type : Type ): List <PythonDefinition > {
162
+ override fun getNamedMembers (type : UtType ): List <PythonDefinition > {
163
163
val functionType = castToCompatibleTypeApi(type)
164
164
return listOf (PythonDefinition (PythonVariableDescription (" __call__" ), functionType))
165
165
}
166
166
167
- override fun getAnnotationParameters (type : Type ): List <Type > {
167
+ override fun getAnnotationParameters (type : UtType ): List <UtType > {
168
168
val functionType = castToCompatibleTypeApi(type)
169
169
return functionType.arguments + listOf (functionType.returnValue)
170
170
}
@@ -178,7 +178,7 @@ class PythonCallableTypeDescription(
178
178
ARG_NAMED_OPT
179
179
}
180
180
181
- override fun createTypeWithNewAnnotationParameters (like : Type , newParams : List <Type >): Type {
181
+ override fun createTypeWithNewAnnotationParameters (like : UtType , newParams : List <UtType >): UtType {
182
182
val args = newParams.dropLast(1 )
183
183
val returnValue = newParams.last()
184
184
return createPythonCallableType(
@@ -200,15 +200,15 @@ class PythonCallableTypeDescription(
200
200
}
201
201
}
202
202
203
- override fun getTypeRepresentation (type : Type ): String {
203
+ override fun getTypeRepresentation (type : UtType ): String {
204
204
val functionType = castToCompatibleTypeApi(type)
205
205
val root = name.prefix.joinToString(" ." ) + " ." + name.name
206
206
return " $root [[${
207
207
functionType.arguments.joinToString(separator = " , " ) { it.pythonTypeRepresentation() }
208
208
} ], ${functionType.returnValue.pythonTypeRepresentation()} ]"
209
209
}
210
210
211
- fun removeNonPositionalArgs (type : Type ): FunctionType {
211
+ fun removeNonPositionalArgs (type : UtType ): FunctionType {
212
212
val functionType = castToCompatibleTypeApi(type)
213
213
val argsCount = argumentKinds.count { it == ArgKind .ARG_POS }
214
214
return createPythonCallableType(
@@ -228,7 +228,7 @@ class PythonCallableTypeDescription(
228
228
}
229
229
}
230
230
231
- fun removeNotRequiredArgs (type : Type ): FunctionType {
231
+ fun removeNotRequiredArgs (type : UtType ): FunctionType {
232
232
val functionType = castToCompatibleTypeApi(type)
233
233
return createPythonCallableType(
234
234
functionType.parameters.size,
@@ -250,7 +250,7 @@ class PythonCallableTypeDescription(
250
250
251
251
// Special Python annotations
252
252
object PythonAnyTypeDescription : PythonSpecialAnnotation(pythonAnyName) {
253
- override fun getMemberByName (storage : PythonTypeStorage , type : Type , name : String ): PythonDefinition {
253
+ override fun getMemberByName (storage : PythonTypeHintsStorage , type : UtType , name : String ): PythonDefinition {
254
254
return PythonDefinition (PythonVariableDescription (name), pythonAnyType)
255
255
}
256
256
}
@@ -260,7 +260,7 @@ object PythonNoneTypeDescription : PythonSpecialAnnotation(pythonNoneName) {
260
260
}
261
261
262
262
object PythonUnionTypeDescription : PythonSpecialAnnotation(pythonUnionName) {
263
- override fun getMemberByName (storage : PythonTypeStorage , type : Type , name : String ): PythonDefinition ? {
263
+ override fun getMemberByName (storage : PythonTypeHintsStorage , type : UtType , name : String ): PythonDefinition ? {
264
264
val children = type.parameters.mapNotNull {
265
265
it.getPythonAttributeByName(storage, name)?.type
266
266
}
@@ -273,28 +273,28 @@ object PythonUnionTypeDescription : PythonSpecialAnnotation(pythonUnionName) {
273
273
)
274
274
}
275
275
276
- override fun getAnnotationParameters (type : Type ): List <Type > = type.parameters
276
+ override fun getAnnotationParameters (type : UtType ): List <UtType > = type.parameters
277
277
}
278
278
279
279
object PythonOverloadTypeDescription : PythonSpecialAnnotation(overloadName) {
280
- override fun getAnnotationParameters (type : Type ): List <Type > = type.parameters
281
- override fun getNamedMembers (type : Type ): List <PythonDefinition > {
280
+ override fun getAnnotationParameters (type : UtType ): List <UtType > = type.parameters
281
+ override fun getNamedMembers (type : UtType ): List <PythonDefinition > {
282
282
return listOf (PythonDefinition (PythonVariableDescription (" __call__" ), type))
283
283
}
284
284
}
285
285
286
286
object PythonTypeAliasDescription : PythonSpecialAnnotation(pythonTypeAliasName) {
287
- override fun castToCompatibleTypeApi (type : Type ): CompositeType {
287
+ override fun castToCompatibleTypeApi (type : UtType ): CompositeType {
288
288
return type as ? CompositeType ? : error(" Got unexpected type for PythonTypeAliasDescription: $type " )
289
289
}
290
- fun getInterior (type : Type ): Type {
290
+ fun getInterior (type : UtType ): UtType {
291
291
val casted = castToCompatibleTypeApi(type)
292
292
return casted.members.first()
293
293
}
294
294
}
295
295
296
296
object PythonTupleTypeDescription : PythonSpecialAnnotation(pythonTupleName) {
297
- override fun getAnnotationParameters (type : Type ): List <Type > = castToCompatibleTypeApi(type).parameters
297
+ override fun getAnnotationParameters (type : UtType ): List <UtType > = castToCompatibleTypeApi(type).parameters
298
298
// TODO: getMemberByName and/or getNamedMembers
299
299
}
300
300
@@ -306,13 +306,13 @@ private fun initTypeVar(param: TypeParameter) {
306
306
)
307
307
}
308
308
309
- private fun substituteMembers (origin : Type , members : List <Type >): Type =
309
+ private fun substituteMembers (origin : UtType , members : List <UtType >): UtType =
310
310
DefaultSubstitutionProvider .substitute(
311
311
origin,
312
312
(origin.parameters.map { it as TypeParameter } zip members).associate { it }
313
313
)
314
314
315
- fun createTypeWithMembers (description : PythonTypeDescription , members : List <Type >): Type {
315
+ fun createTypeWithMembers (description : PythonTypeDescription , members : List <UtType >): UtType {
316
316
val origin = TypeCreator .create(members.size, description) {
317
317
it.parameters.forEach(::initTypeVar)
318
318
}
0 commit comments