def _best_transform_to(self, target_type: Type[T], source_types: Iterable[Type]) -> Tuple[Callable[[T], Any], Type, int]:
best = None
best_cost = _MAX_TRANSFORM_COST
from_type = None
for source_type in source_types:
try:
transform, cost = self._transform(source_type, target_type)
if cost < best_cost:
best = transform
best_cost = cost
from_type = source_type
except NoConversionError:
pass
if best is None:
raise NoConversionError("Pipeline can't convert from any of \"{source_types}\" to \"{target_type}\"".format(source_types=source_types, target_type=target_type))
return best, from_type, best_cost
pipelines.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录