|
1 | 1 | import re |
2 | 2 | from code_template import CodeTemplate |
3 | 3 |
|
| 4 | +import sys |
| 5 | +if sys.version_info[0] == 3: |
| 6 | + string_type = str |
| 7 | +else: |
| 8 | + string_type = basestring |
| 9 | + |
4 | 10 | # temporary things we cannot handle |
5 | 11 | EXCLUDE_PATTERN = "bernoulli.*|normal.*|exponential.*|random.*|arange.*" |
6 | 12 | # what has to be done to add a Operation ... |
@@ -272,14 +278,21 @@ def create_derived(backend_type_env, declarations): |
272 | 278 | def requires_checked_cast(argument): |
273 | 279 | return argument['type'] in CHECKED_CAST |
274 | 280 |
|
| 281 | + def bool_option_is_string(argument): |
| 282 | + return 'if_true' in argument and isinstance(argument['if_true'], string_type) |
| 283 | + |
275 | 284 | def get_argument(argument, option): |
276 | 285 | if requires_checked_cast(argument): |
277 | 286 | return CHECKED_USE.get(argument['type'], '{}_').format(argument['name']) |
278 | 287 | elif argument['type'] == 'bool' and 'if_true' in argument: |
279 | | - return '({}) ? "{}" : "{}"'.format(argument['name'], |
280 | | - argument['if_true'], argument['if_false']) |
| 288 | + if bool_option_is_string(argument): |
| 289 | + tpl = '({}) ? "{}" : "{}"' |
| 290 | + else: |
| 291 | + tpl = '({}) ? {} : {}' |
| 292 | + return tpl.format(argument['name'], |
| 293 | + argument['if_true'], argument['if_false']) |
281 | 294 | elif argument['type'] == "CONSTANT": |
282 | | - if 'if_true' in argument: # this was a bool that is actually a string... |
| 295 | + if bool_option_is_string(argument): # this is a bool that is actually a string... |
283 | 296 | return '"{}"'.format(argument['name']) |
284 | 297 | v = str(argument['name']) |
285 | 298 | for pattern, replacement in CONSTANT_REPLACEMENTS: |
|
0 commit comments