Parse the answer according to the question's type.
(self, answer: Any)
| 496 | raise UserMessageError(str(error)) from error |
| 497 | |
| 498 | def parse_answer(self, answer: Any) -> Any: |
| 499 | """Parse the answer according to the question's type.""" |
| 500 | if self.multiselect: |
| 501 | # If the answer to a multiselect question is a string (typically because |
| 502 | # the default value is templated), then it must be a serialized YAML-style |
| 503 | # list of choice items. Thus, we shallowly parse the outermost list first, |
| 504 | # then we parse the items according to the `type: <type>` field. |
| 505 | if isinstance(answer, str): |
| 506 | answer = parse_yaml_list(answer) |
| 507 | answer = [self._parse_answer(a) for a in answer] |
| 508 | choices = ( |
| 509 | self.cast_answer(choice.value) for choice in self._formatted_choices |
| 510 | ) |
| 511 | return [choice for choice in choices if choice in answer] |
| 512 | return self._parse_answer(answer) |
| 513 | |
| 514 | def _parse_answer(self, answer: Any) -> Any: |
| 515 | """Parse a single answer according to the question's type.""" |
no test coverage detected