From 86cfbc22b1cebdde998f9705a7a7b8aba94b5b7e Mon Sep 17 00:00:00 2001 From: Fireclaw Date: Mon, 15 Jun 2020 11:29:46 +0200 Subject: [PATCH] direct: Fix errors in PythonUtil.detectLeaks() function (#955) * Replaced removed choice() function with ternary expression * Add sanity check for _crashOnProactiveLeakDetect, don't crash by default Closes #955 --- direct/src/showbase/DirectObject.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/direct/src/showbase/DirectObject.py b/direct/src/showbase/DirectObject.py index 778328ea50..0833b1890a 100644 --- a/direct/src/showbase/DirectObject.py +++ b/direct/src/showbase/DirectObject.py @@ -94,12 +94,12 @@ class DirectObject: if hasattr(self, '_taskList'): tasks = [task.name for task in self._taskList.values()] if len(events) or len(tasks): - estr = choice(len(events), 'listening to events: %s' % events, '') - andStr = choice(len(events) and len(tasks), ' and ', '') - tstr = choice(len(tasks), '%srunning tasks: %s' % (andStr, tasks), '') + estr = ('listening to events: %s' % events if len(events) else '') + andStr = (' and ' if len(events) and len(tasks) else '') + tstr = ('%srunning tasks: %s' % (andStr, tasks) if len(tasks) else '') notify = directNotify.newCategory('LeakDetect') - func = choice(getRepository()._crashOnProactiveLeakDetect, - self.notify.error, self.notify.warning) + crash = getattr(getRepository(), '_crashOnProactiveLeakDetect', False) + func = (self.notify.error if crash else self.notify.warning) func('destroyed %s instance is still %s%s' % (self.__class__.__name__, estr, tstr)) #snake_case alias: