Skip to content

Commit 2ef9ae5

Browse files
committed
Added some null checks
1 parent 4e6936e commit 2ef9ae5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,18 @@ abstract class PythonTestGenerationProcessor {
235235
var containingClass: CompositeType? = null
236236
val containingClassName = method.containingPythonClassId?.simpleName
237237
val definition = if (containingClassName == null) {
238-
mypyStorage.definitions[curModule]!![method.name]!!.getUtBotDefinition()!!
238+
mypyStorage.definitions[curModule]?.get(method.name)?.getUtBotDefinition()
239239
} else {
240240
containingClass =
241-
mypyStorage.definitions[curModule]!![containingClassName]!!.getUtBotType() as CompositeType
241+
mypyStorage.definitions[curModule]?.get(containingClassName)?.getUtBotType() as? CompositeType
242+
?: throw SelectedMethodIsNotAFunctionDefinition(method.name)
242243
val descr = containingClass.pythonDescription()
243244
if (descr !is PythonConcreteCompositeTypeDescription)
244245
throw SelectedMethodIsNotAFunctionDefinition(method.name)
245-
mypyStorage.definitions[curModule]!![containingClassName]!!.type.asUtBotType.getPythonAttributes().first {
246+
mypyStorage.definitions[curModule]?.get(containingClassName)?.type?.asUtBotType?.getPythonAttributes()?.first {
246247
it.meta.name == method.name
247248
}
248-
}
249+
} ?: throw SelectedMethodIsNotAFunctionDefinition(method.name)
249250
val parsedFile = PythonParser(sourceFileContent).Module()
250251
val funcDef = PythonCode.findFunctionDefinition(parsedFile, method)
251252
val decorators = funcDef.decorators.map { PyDecorator.decoratorByName(it.name.toString()) }

0 commit comments

Comments
 (0)