@@ -5,15 +5,15 @@ import org.utbot.python.newtyping.general.Name
55import org.utbot.python.newtyping.utils.isRequired
66
77sealed 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 ? =
1212 // overridden for some types
1313 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
1515 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
1717 if (name.prefix == listOf (" builtins" ) && name.name == " tuple" ) {
1818 return " ${getTypeName()} [${type.parameters.first().pythonTypeRepresentation()} , ...]"
1919 }
@@ -35,7 +35,7 @@ sealed class PythonTypeDescription(name: Name) : TypeMetaDataWithName(name) {
3535 fun getName (): String {
3636 return name.name
3737 }
38- fun getModules (type : Type ): Set <String > {
38+ fun getModules (type : UtType ): Set <String > {
3939 val cur = if (name.prefix.isNotEmpty())
4040 setOf (name.prefix.joinToString(separator = " ." ))
4141 else
@@ -50,12 +50,12 @@ sealed class PythonCompositeTypeDescription(
5050 name : Name ,
5151 private val memberDescriptions : List <PythonDefinitionDescription >
5252): PythonTypeDescription(name) {
53- override fun castToCompatibleTypeApi (type : Type ): CompositeType {
53+ override fun castToCompatibleTypeApi (type : UtType ): CompositeType {
5454 return type as ? CompositeType
5555 ? : error(" Got unexpected type PythonCompositeTypeDescription: $type " )
5656 }
5757
58- override fun getNamedMembers (type : Type ): List <PythonDefinition > {
58+ override fun getNamedMembers (type : UtType ): List <PythonDefinition > {
5959 val compositeType = castToCompatibleTypeApi(type)
6060 assert (compositeType.members.size == memberDescriptions.size)
6161 return (memberDescriptions zip compositeType.members).map { (descr, typ) ->
@@ -66,8 +66,8 @@ sealed class PythonCompositeTypeDescription(
6666 }
6767 }
6868
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 > {
7171 val compositeType = castToCompatibleTypeApi(type)
7272 var bases = compositeType.supertypes
7373 if (bases.isEmpty() && ! type.isPythonObjectType())
@@ -82,7 +82,7 @@ sealed class PythonCompositeTypeDescription(
8282 linBases.removeIf { it.isEmpty() }
8383 if (linBases.isEmpty())
8484 break
85- lateinit var addAtThisIteration: Type
85+ lateinit var addAtThisIteration: UtType
8686 for (seq in linBases) {
8787 val head = seq.first()
8888 val isContainedSomewhereElse = linBases.any {
@@ -102,7 +102,7 @@ sealed class PythonCompositeTypeDescription(
102102 return result
103103 }
104104
105- override fun getMemberByName (storage : PythonTypeStorage , type : Type , name : String ): PythonDefinition ? {
105+ override fun getMemberByName (storage : PythonTypeHintsStorage , type : UtType , name : String ): PythonDefinition ? {
106106 for (parent in mro(storage, type)) {
107107 val cur = parent.getPythonAttributes().find { it.meta.name == name }
108108 if (cur != null )
@@ -119,7 +119,7 @@ class PythonTypeVarDescription(
119119 val variance : Variance ,
120120 val parameterKind : ParameterKind
121121) : PythonTypeDescription(name) {
122- override fun castToCompatibleTypeApi (type : Type ): TypeParameter {
122+ override fun castToCompatibleTypeApi (type : UtType ): TypeParameter {
123123 return type as ? TypeParameter
124124 ? : error(" Got unexpected type PythonTypeVarDescription: $type " )
125125 }
@@ -154,17 +154,17 @@ class PythonCallableTypeDescription(
154154 val argumentNames : List <String ?> // like in mypy's CallableType: https://github.com/python/mypy/blob/master/mypy/types.py#L1672
155155): PythonTypeDescription(pythonCallableName) {
156156 val numberOfArguments = argumentKinds.size
157- override fun castToCompatibleTypeApi (type : Type ): FunctionType {
157+ override fun castToCompatibleTypeApi (type : UtType ): FunctionType {
158158 return type as ? FunctionType
159159 ? : error(" Got unexpected type PythonCallableTypeDescription: $type " )
160160 }
161161
162- override fun getNamedMembers (type : Type ): List <PythonDefinition > {
162+ override fun getNamedMembers (type : UtType ): List <PythonDefinition > {
163163 val functionType = castToCompatibleTypeApi(type)
164164 return listOf (PythonDefinition (PythonVariableDescription (" __call__" ), functionType))
165165 }
166166
167- override fun getAnnotationParameters (type : Type ): List <Type > {
167+ override fun getAnnotationParameters (type : UtType ): List <UtType > {
168168 val functionType = castToCompatibleTypeApi(type)
169169 return functionType.arguments + listOf (functionType.returnValue)
170170 }
@@ -178,7 +178,7 @@ class PythonCallableTypeDescription(
178178 ARG_NAMED_OPT
179179 }
180180
181- override fun createTypeWithNewAnnotationParameters (like : Type , newParams : List <Type >): Type {
181+ override fun createTypeWithNewAnnotationParameters (like : UtType , newParams : List <UtType >): UtType {
182182 val args = newParams.dropLast(1 )
183183 val returnValue = newParams.last()
184184 return createPythonCallableType(
@@ -200,15 +200,15 @@ class PythonCallableTypeDescription(
200200 }
201201 }
202202
203- override fun getTypeRepresentation (type : Type ): String {
203+ override fun getTypeRepresentation (type : UtType ): String {
204204 val functionType = castToCompatibleTypeApi(type)
205205 val root = name.prefix.joinToString(" ." ) + " ." + name.name
206206 return " $root [[${
207207 functionType.arguments.joinToString(separator = " , " ) { it.pythonTypeRepresentation() }
208208 } ], ${functionType.returnValue.pythonTypeRepresentation()} ]"
209209 }
210210
211- fun removeNonPositionalArgs (type : Type ): FunctionType {
211+ fun removeNonPositionalArgs (type : UtType ): FunctionType {
212212 val functionType = castToCompatibleTypeApi(type)
213213 val argsCount = argumentKinds.count { it == ArgKind .ARG_POS }
214214 return createPythonCallableType(
@@ -228,7 +228,7 @@ class PythonCallableTypeDescription(
228228 }
229229 }
230230
231- fun removeNotRequiredArgs (type : Type ): FunctionType {
231+ fun removeNotRequiredArgs (type : UtType ): FunctionType {
232232 val functionType = castToCompatibleTypeApi(type)
233233 return createPythonCallableType(
234234 functionType.parameters.size,
@@ -250,7 +250,7 @@ class PythonCallableTypeDescription(
250250
251251// Special Python annotations
252252object 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 {
254254 return PythonDefinition (PythonVariableDescription (name), pythonAnyType)
255255 }
256256}
@@ -260,7 +260,7 @@ object PythonNoneTypeDescription : PythonSpecialAnnotation(pythonNoneName) {
260260}
261261
262262object 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 ? {
264264 val children = type.parameters.mapNotNull {
265265 it.getPythonAttributeByName(storage, name)?.type
266266 }
@@ -273,28 +273,28 @@ object PythonUnionTypeDescription : PythonSpecialAnnotation(pythonUnionName) {
273273 )
274274 }
275275
276- override fun getAnnotationParameters (type : Type ): List <Type > = type.parameters
276+ override fun getAnnotationParameters (type : UtType ): List <UtType > = type.parameters
277277}
278278
279279object 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 > {
282282 return listOf (PythonDefinition (PythonVariableDescription (" __call__" ), type))
283283 }
284284}
285285
286286object PythonTypeAliasDescription : PythonSpecialAnnotation(pythonTypeAliasName) {
287- override fun castToCompatibleTypeApi (type : Type ): CompositeType {
287+ override fun castToCompatibleTypeApi (type : UtType ): CompositeType {
288288 return type as ? CompositeType ? : error(" Got unexpected type for PythonTypeAliasDescription: $type " )
289289 }
290- fun getInterior (type : Type ): Type {
290+ fun getInterior (type : UtType ): UtType {
291291 val casted = castToCompatibleTypeApi(type)
292292 return casted.members.first()
293293 }
294294}
295295
296296object 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
298298 // TODO: getMemberByName and/or getNamedMembers
299299}
300300
@@ -306,13 +306,13 @@ private fun initTypeVar(param: TypeParameter) {
306306 )
307307}
308308
309- private fun substituteMembers (origin : Type , members : List <Type >): Type =
309+ private fun substituteMembers (origin : UtType , members : List <UtType >): UtType =
310310 DefaultSubstitutionProvider .substitute(
311311 origin,
312312 (origin.parameters.map { it as TypeParameter } zip members).associate { it }
313313 )
314314
315- fun createTypeWithMembers (description : PythonTypeDescription , members : List <Type >): Type {
315+ fun createTypeWithMembers (description : PythonTypeDescription , members : List <UtType >): UtType {
316316 val origin = TypeCreator .create(members.size, description) {
317317 it.parameters.forEach(::initTypeVar)
318318 }
0 commit comments