|
12 | 12 | import warnings
|
13 | 13 | import re
|
14 | 14 | import logging
|
| 15 | +import pprint |
15 | 16 |
|
16 | 17 | from functools import wraps
|
17 | 18 |
|
@@ -754,15 +755,47 @@ def _validate_callback(self, output, inputs, state, events):
|
754 | 755 | ).replace(' ', ''))
|
755 | 756 |
|
756 | 757 | callback_id = _create_callback_id(output)
|
757 |
| - if callback_id in self.callback_map: |
758 |
| - raise exceptions.CantHaveMultipleOutputs(''' |
| 758 | + is_multi = isinstance(output, (list, tuple)) |
| 759 | + callbacks = set(itertools.chain(*( |
| 760 | + x[1:-1].split(':') |
| 761 | + if x.startswith('[') |
| 762 | + else [x] |
| 763 | + for x in self.callback_map |
| 764 | + ))) |
| 765 | + ns = { |
| 766 | + 'duplicates': callback_id |
| 767 | + } |
| 768 | + if is_multi: |
| 769 | + def duplicate_check(): |
| 770 | + ns['duplicates'] = intersection = callbacks.intersection( |
| 771 | + _create_callback_id(y) for y in output |
| 772 | + ) |
| 773 | + return intersection |
| 774 | + else: |
| 775 | + def duplicate_check(): |
| 776 | + return callback_id in callbacks |
| 777 | + if duplicate_check(): |
| 778 | + if is_multi: |
| 779 | + msg = ''' |
| 780 | + Multi output {} contains an `Output` object |
| 781 | + that was already assigned. |
| 782 | + Duplicates: |
| 783 | + {} |
| 784 | + '''.format( |
| 785 | + callback_id, |
| 786 | + pprint.pformat((ns['duplicates'])) |
| 787 | + ) |
| 788 | + else: |
| 789 | + msg = ''' |
759 | 790 | You have already assigned a callback to the output
|
760 | 791 | with ID "{}" and property "{}". An output can only have
|
761 | 792 | a single callback function. Try combining your inputs and
|
762 | 793 | callback functions together into one function.
|
763 |
| - '''.format( |
764 |
| - output.component_id, |
765 |
| - output.component_property).replace(' ', '')) |
| 794 | + '''.format( |
| 795 | + output.component_id, |
| 796 | + output.component_property |
| 797 | + ).replace(' ', '') |
| 798 | + raise exceptions.CantHaveMultipleOutputs(msg) |
766 | 799 |
|
767 | 800 | def _validate_callback_output(self, output_value, output):
|
768 | 801 | valid = [str, dict, int, float, type(None), Component]
|
|
0 commit comments