Skip to content

Commit 7f6dc67

Browse files
author
cool-RR
committed
-
1 parent ac4e599 commit 7f6dc67

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

garlicsim/garlicsim/asynchronous_crunching/crunching_manager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ def __init__(self, project):
8989
job they're working on has changed.
9090
'''
9191

92-
self.cruncher_type = \
93-
self.project.simpack_grokker.available_cruncher_types[0]
92+
try:
93+
self.cruncher_type = \
94+
self.project.simpack_grokker.available_cruncher_types[0]
95+
except IndexError:
96+
raise garlicsim.misc.GarlicSimException(
97+
"The `%s` simpack doesn't allow using any of the cruncher "
98+
"types we have installed." % self.project.simpack.__name__
99+
)
94100

95101

96102
@with_tree_lock

garlicsim/garlicsim/general_misc/misc_tools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
from . import import_tools
1111

1212

13+
def is_subclass(candidate, base_class):
14+
'''
15+
You may pass in a tuple of base classes instead of just one, and it will
16+
check whether `candidate` is a subclass of any of these base classes.
17+
'''
18+
# The reason to use this wrapper is that `issubclass` sometimes fails on
19+
# non-type candidates. (Python issue 10569.)
20+
return isinstance(candidate, (type, types.ClassType)) and \
21+
issubclass(candidate, base_class)
22+
1323
def frange(start, finish=None, step=1.):
1424
'''
1525
Make a list containing an arithmetic progression of numbers.

garlicsim/garlicsim/misc/simpack_grokker/simpack_grokker.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init_analysis(self):
5757
raise InvalidSimpack("The %s simpack does not define a `State` "
5858
"class." % simpack.__name__)
5959

60-
if not issubclass(State, garlicsim.data_structures.State):
60+
if not misc_tools.is_subclass(State, garlicsim.data_structures.State):
6161
raise InvalidSimpack("The %s simpack defines a State class, but "
6262
"it's not a subclass of "
6363
"`garlicsim.data_structures.State`." % \
@@ -200,7 +200,7 @@ def __init_analysis_cruncher_types(self):
200200
###################################################################
201201

202202

203-
elif isinstance(CRUNCHERS, BaseCruncher):
203+
elif misc_tools.is_subclass(CRUNCHERS, BaseCruncher):
204204
cruncher_type = CRUNCHERS
205205
self.available_cruncher_types = [cruncher_type]
206206
self.cruncher_types_availability[cruncher_type] = True
@@ -226,16 +226,16 @@ def __init_analysis_cruncher_types(self):
226226
###################################################################
227227

228228

229-
elif cute_iter_tools.is_iterable(CRUNCHERS):
229+
elif cute_iter_tools.is_iterable(CRUNCHERS):
230230
self.available_cruncher_types = []
231231
for item in CRUNCHERS:
232232
if isinstance(item, basestring):
233-
cruncher_type = \
233+
(cruncher_type,) = \
234234
[cruncher_type_ for cruncher_type_ in
235235
crunchers.cruncher_types_list if
236236
cruncher_type_.__name__ == item]
237237
else:
238-
assert isinstance(item, BaseCruncher)
238+
assert misc_tools.is_subclass(item, BaseCruncher)
239239
cruncher_type = item
240240
self.available_cruncher_types.append(cruncher_type)
241241
self.cruncher_types_availability[cruncher_type] = True
@@ -268,7 +268,6 @@ def __init_analysis_cruncher_types(self):
268268
[cruncher_type_ for cruncher_type_ in
269269
crunchers.cruncher_types_list if
270270
CRUNCHERS(cruncher_type_)]
271-
self.cruncher_type = self.available_cruncher_types[0]
272271
for available_cruncher_type in self.available_cruncher_types:
273272
self.cruncher_types_availability[available_cruncher_type] = \
274273
True
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from life import *
22

33
DETERMINISM_FUNCTION = determinism_function
4+
45
#SCALAR_STATE_FUNCTIONS = [State.get_n_live_cells]
56
#SCALAR_HISTORY_FUNCTIONS = [changes]

0 commit comments

Comments
 (0)