option_together can be either a tuple of tuples, or a single tuple of two strings. Normalize it to a tuple of tuples, so that calling code can uniformly expect that.
(option_together)
| 62 | |
| 63 | |
| 64 | def normalize_together(option_together): |
| 65 | """ |
| 66 | option_together can be either a tuple of tuples, or a single |
| 67 | tuple of two strings. Normalize it to a tuple of tuples, so that |
| 68 | calling code can uniformly expect that. |
| 69 | """ |
| 70 | try: |
| 71 | if not option_together: |
| 72 | return () |
| 73 | if not isinstance(option_together, (tuple, list)): |
| 74 | raise TypeError |
| 75 | first_element = option_together[0] |
| 76 | if not isinstance(first_element, (tuple, list)): |
| 77 | option_together = (option_together,) |
| 78 | # Normalize everything to tuples |
| 79 | return tuple(tuple(ot) for ot in option_together) |
| 80 | except TypeError: |
| 81 | # If the value of option_together isn't valid, return it |
| 82 | # verbatim; this will be picked up by the check framework later. |
| 83 | return option_together |
| 84 | |
| 85 | |
| 86 | def make_immutable_fields_list(name, data): |
no outgoing calls
no test coverage detected