MCPcopy Index your code
hub / github.com/pyinvoke/invoke / _normalize

Method _normalize

invoke/context.py:515–528  ·  view source on GitHub ↗
(self, value: Any)

Source from the content-addressed store, hash-verified

513 self._set(method, Mock(wraps=getattr(self, method)))
514
515 def _normalize(self, value: Any) -> Iterator[Any]:
516 # First turn everything into an iterable
517 if not hasattr(value, "__iter__") or isinstance(value, str):
518 value = [value]
519 # Then turn everything within into a Result
520 results = []
521 for obj in value:
522 if isinstance(obj, bool):
523 obj = Result(exited=0 if obj else 1)
524 elif isinstance(obj, str):
525 obj = Result(obj)
526 results.append(obj)
527 # Finally, turn that iterable into an iteratOR, depending on repeat
528 return cycle(results) if getattr(self, "__repeat") else iter(results)
529
530 # TODO: _maybe_ make this more metaprogrammy/flexible (using __call__ etc)?
531 # Pretty worried it'd cause more hard-to-debug issues than it's presently

Callers 2

__init__Method · 0.95
set_result_forMethod · 0.95

Calls 1

ResultClass · 0.85

Tested by

no test coverage detected