Skip to content

Commit

Permalink
[mlir] Fix copy-pasted docstrings in Python bindings
Browse files Browse the repository at this point in the history
Docstrings for `__str__` method in many classes was recycling the constant
string defined for `Type`, without being types themselves. Use proper
docstrings instead. Since they are succint, use string literals instead of
top-level constants to avoid further mistakes.

Differential Revision: https://reviews.llvm.org/D89780
  • Loading branch information
ftynse committed Oct 21, 2020
1 parent 31782cd commit f6f2711
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions mlir/lib/Bindings/Python/IRModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ use the dedicated print method, which supports keyword arguments to customize
behavior.
)";

static const char kTypeStrDunderDocstring[] =
R"(Prints the assembly form of the type.)";

static const char kDumpDocstring[] =
R"(Dumps a debug representation of the object to stderr.)";

Expand Down Expand Up @@ -1978,7 +1975,7 @@ void mlir::python::populateIRSubmodule(py::module &m) {
printAccum.getUserData());
return printAccum.join();
},
kTypeStrDunderDocstring);
"Returns the assembly form of the operation.");

// Mapping of PyRegion.
py::class_<PyRegion>(m, "Region")
Expand Down Expand Up @@ -2047,9 +2044,9 @@ void mlir::python::populateIRSubmodule(py::module &m) {
printAccum.getUserData());
return printAccum.join();
},
kTypeStrDunderDocstring);
"Returns the assembly form of the block.");

// Mapping of Type.
// Mapping of PyAttribute.
py::class_<PyAttribute>(m, "Attribute")
.def_property_readonly(
"context",
Expand Down Expand Up @@ -2086,7 +2083,7 @@ void mlir::python::populateIRSubmodule(py::module &m) {
printAccum.getUserData());
return printAccum.join();
},
kTypeStrDunderDocstring)
"Returns the assembly form of the Attribute.")
.def("__repr__", [](PyAttribute &self) {
// Generally, assembly formats are not printed for __repr__ because
// this can cause exceptionally long debug output and exceptions.
Expand Down Expand Up @@ -2139,7 +2136,7 @@ void mlir::python::populateIRSubmodule(py::module &m) {
PyStringAttribute::bind(m);
PyDenseElementsAttribute::bind(m);

// Mapping of Type.
// Mapping of PyType.
py::class_<PyType>(m, "Type")
.def_property_readonly(
"context", [](PyType &self) { return self.getContext().getObject(); },
Expand All @@ -2163,7 +2160,7 @@ void mlir::python::populateIRSubmodule(py::module &m) {
printAccum.getUserData());
return printAccum.join();
},
kTypeStrDunderDocstring)
"Returns the assembly form of the type.")
.def("__repr__", [](PyType &self) {
// Generally, assembly formats are not printed for __repr__ because
// this can cause exceptionally long debug output and exceptions.
Expand Down

0 comments on commit f6f2711

Please sign in to comment.