示例#1
0
 def _make_converter(self):
     # Creates system scalar converter for the template class.
     converter = SystemScalarConverter()
     # N.B. This does not directly instantiate the template; it is deferred
     # to when the conversion is called.
     for (T, U) in self._T_pairs:
         conversion = partial(self._make, T, U)
         converter.Add[T, U](conversion)
     return converter
    def _make_converter(self):
        # Creates system scalar converter for the template class.
        converter = SystemScalarConverter()

        # Define capture to ensure the current values are bound, and do not
        # change through iteration.
        # N.B. This does not directly instantiate the template; it is deferred
        # to when the conversion is called.
        def add_captured(T_pair):
            T, U = T_pair

            def conversion(system):
                assert isinstance(system, self[U])
                return self[T](system)

            converter.Add[T, U](conversion)

        map(add_captured, self._T_pairs)
        return converter