Skip to content

Commit 1a8752b

Browse files
davidberard98pytorchmergebot
authored andcommitted
[TorchScript] bindings for torch._C.ClassType.method_names() (pytorch#140444)
I used this for debugging, figured I'd upstream it. This gives you a list of the method names provided by the given ClassType. Pull Request resolved: pytorch#140444 Approved by: https://github.com/eellison
1 parent 2675ef8 commit 1a8752b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

torch/csrc/jit/python/python_ir.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,15 @@ void initPythonIRBindings(PyObject* module_) {
10711071
return get_python_cu()->get_class(c10::QualifiedName(qualified_name));
10721072
}))
10731073
.def("name", [](ClassType& self) { return self.name()->name(); })
1074-
.def("qualified_name", [](ClassType& self) {
1075-
return self.name()->qualifiedName();
1074+
.def(
1075+
"qualified_name",
1076+
[](ClassType& self) { return self.name()->qualifiedName(); })
1077+
.def("method_names", [](ClassType& self) {
1078+
std::vector<std::string> method_names;
1079+
for (const auto* method : self.methods()) {
1080+
method_names.push_back(method->name());
1081+
}
1082+
return method_names;
10761083
});
10771084
py::class_<EnumType, Type, EnumTypePtr>(m, "EnumType")
10781085
.def(py::init([](const std::string& qualified_name,

0 commit comments

Comments
 (0)