diff --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp --- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp +++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp @@ -20,7 +20,7 @@ py::module m, const py::module &irModule) { auto attributeClass = irModule.attr("Attribute"); - py::enum_(m, "DimLevelType") + py::enum_(m, "DimLevelType", py::module_local()) .value("dense", MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE) .value("compressed", MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED) .value("singleton", MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON); diff --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h --- a/mlir/lib/Bindings/Python/IRModule.h +++ b/mlir/lib/Bindings/Python/IRModule.h @@ -678,7 +678,8 @@ } static void bind(pybind11::module &m) { - auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::buffer_protocol()); + auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::buffer_protocol(), + pybind11::module_local()); cls.def(pybind11::init(), pybind11::keep_alive<0, 1>()); DerivedTy::bindDerived(cls); } @@ -741,7 +742,7 @@ } static void bind(pybind11::module &m) { - auto cls = ClassTy(m, DerivedTy::pyClassName); + auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::module_local()); cls.def(pybind11::init(), pybind11::keep_alive<0, 1>()); cls.def_static("isinstance", [](PyType &otherType) -> bool { return DerivedTy::isaFunction(otherType); diff --git a/mlir/lib/Bindings/Python/PybindUtils.h b/mlir/lib/Bindings/Python/PybindUtils.h --- a/mlir/lib/Bindings/Python/PybindUtils.h +++ b/mlir/lib/Bindings/Python/PybindUtils.h @@ -262,7 +262,8 @@ /// Binds the indexing and length methods in the Python class. static void bind(pybind11::module &m) { - auto clazz = pybind11::class_(m, Derived::pyClassName) + auto clazz = pybind11::class_(m, Derived::pyClassName, + pybind11::module_local()) .def("__len__", &Sliceable::dunderLen) .def("__getitem__", &Sliceable::dunderGetItem) .def("__getitem__", &Sliceable::dunderGetItemSlice);