MCPcopy Create free account
hub / github.com/copier-org/copier / parse_answer

Method parse_answer

copier/_user_data.py:498–512  ·  view source on GitHub ↗

Parse the answer according to the question's type.

(self, answer: Any)

Source from the content-addressed store, hash-verified

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."""

Callers 3

_askMethod · 0.95
get_defaultMethod · 0.95
_validateMethod · 0.95

Calls 3

_parse_answerMethod · 0.95
cast_answerMethod · 0.95
parse_yaml_listFunction · 0.85

Tested by

no test coverage detected