Repository: onnx/onnx
File: onnx/cpp2py_export.cc (C++)

Code before:
    auto* dst = self.getOutputType(idx);
    if (dst == nullptr) {
      return false;
    }
    dst->CopyFrom(src);
    return true;
  });
  inference_ctx.def("has_output", &InferenceContext::hasOutput);
  inference_ctx.def(
      "get_graph_attribute_inferencer",
      &InferenceContext::getGraphAttributeInferencer,
      py::return_value_policy::reference_internal);
  inference_ctx.def("get_input_sparse_data", &InferenceContext::getInputSparseData);
  inference_ctx.def("get_symbolic_input", &InferenceContext::getSymbolicInput);
  inference_ctx.def("get_display_name", &InferenceContext::getDisplayName);

  py::class_<GraphInferencer> graph_inferencer(shape_inference, "GraphInferencer", "Graph Inferencer");
  graph_inferencer.def(
      "do_inferencing",
      [](GraphInferencer& self,
         const std::vector<py::object>& inputTypesObj,
         const std::vector<py::object>& inputDataObj) {
        auto inputTypesTuple = ConvertPyObjToPtr<ONNX_NAMESPACE::TypeProto>(inputTypesObj);
        auto inputDataTuple = ConvertPyObjToPtr<ONNX_NAMESPACE::TensorProto>(inputDataObj);
        auto ret = self.doInferencing(std::get<1>(inputTypesTuple), std::get<1>(inputDataTuple));
        std::vector<py::object> retObj(ret.size());
        for (size_t i = 0; i < ret.size(); ++i) {
          retObj[i] = py::cast(ret[i]);
        }
        return retObj;
      });

  shape_inference.def(
      "infer_shapes",
      [](const py::bytes& bytes, bool check_type, bool strict_mode, bool data_prop) {
        ModelProto proto{};
        ParseProtoFromPyBytes(&proto, bytes);
        ShapeInferenceOptions options{check_type, strict_mode ? 1 : 0, data_prop};
        shape_inference::InferShapes(proto, OpSchemaRegistry::Instance(), options);
        std::string out;
        proto.SerializeToString(&out);
        return py::bytes(out);
      },
      "bytes"_a,
      "check_type"_a = false,
      "strict_mode"_a = false,
      "data_prop"_a = false);

  shape_inference.def(
      "infer_shapes_path",
      [](const std::string& model_path,

Review comment (suggestion):
```suggestion
        std::vector<py::object> ret_obj(ret.size());
```

nit: Use snake_case for variable names

Code after:
    auto* dst = self.getOutputType(idx);
    if (dst == nullptr) {
      return false;
    }
    dst->CopyFrom(src);
    return true;
  });
  inference_context.def("has_output", &InferenceContext::hasOutput);
  inference_context.def(
      "get_graph_attribute_inferencer",
      &InferenceContext::getGraphAttributeInferencer,
      py::return_value_policy::reference_internal);
  inference_context.def("get_input_sparse_data", &InferenceContext::getInputSparseData);
  inference_context.def("get_symbolic_input", &InferenceContext::getSymbolicInput);
  inference_context.def("get_display_name", &InferenceContext::getDisplayName);

  py::class_<GraphInferencer> graph_inferencer(shape_inference, "GraphInferencer", "Graph Inferencer");
  graph_inferencer.def(
      "do_inferencing",
      [](GraphInferencer& self,
         const std::vector<py::object>& inputTypesObj,
         const std::vector<py::object>& inputDataObj) {
        auto inputTypesTuple = ConvertPyObjToPtr<ONNX_NAMESPACE::TypeProto>(inputTypesObj);
        auto inputDataTuple = ConvertPyObjToPtr<ONNX_NAMESPACE::TensorProto>(inputDataObj);
        auto ret = self.doInferencing(std::get<1>(inputTypesTuple), std::get<1>(inputDataTuple));
        std::vector<py::object> ret_obj(ret.size());
        for (size_t i = 0; i < ret.size(); ++i) {
          ret_obj[i] = py::cast(ret[i]);
        }
        return ret_obj;
      });

  shape_inference.def(
      "infer_shapes",
      [](const py::bytes& bytes, bool check_type, bool strict_mode, bool data_prop) {
        ModelProto proto{};
        ParseProtoFromPyBytes(&proto, bytes);
        ShapeInferenceOptions options{check_type, strict_mode ? 1 : 0, data_prop};
        shape_inference::InferShapes(proto, OpSchemaRegistry::Instance(), options);
        std::string out;
        proto.SerializeToString(&out);
        return py::bytes(out);
      },
      "bytes"_a,
      "check_type"_a = false,
      "strict_mode"_a = false,
      "data_prop"_a = false);

  shape_inference.def(
      "infer_shapes_path",
      [](const std::string& model_path,