@@ -1605,7 +1605,9 @@ class PyConcreteValue : public PyValue {
16051605 },
16061606 nb::arg (" other_value" ));
16071607 cls.def (MLIR_PYTHON_MAYBE_DOWNCAST_ATTR,
1608- [](DerivedTy &self) { return self.maybeDownCast (); });
1608+ [](DerivedTy &self) -> nb::typed<nb::object, DerivedTy> {
1609+ return self.maybeDownCast ();
1610+ });
16091611 DerivedTy::bindDerived (cls);
16101612 }
16111613
@@ -1638,9 +1640,9 @@ class PyOpResult : public PyConcreteValue<PyOpResult> {
16381640
16391641// / Returns the list of types of the values held by container.
16401642template <typename Container>
1641- static std::vector<nb::object> getValueTypes (Container &container,
1642- PyMlirContextRef &context) {
1643- std::vector<nb::object> result;
1643+ static std::vector<nb::typed<nb:: object, PyType>>
1644+ getValueTypes (Container &container, PyMlirContextRef &context) {
1645+ std::vector<nb::typed<nb:: object, PyType> > result;
16441646 result.reserve (container.size ());
16451647 for (int i = 0 , e = container.size (); i < e; ++i) {
16461648 result.push_back (PyType (context->getRef (),
@@ -2677,7 +2679,8 @@ class PyOpAttributeMap {
26772679 PyOpAttributeMap (PyOperationRef operation)
26782680 : operation(std::move(operation)) {}
26792681
2680- nb::object dunderGetItemNamed (const std::string &name) {
2682+ nb::typed<nb::object, PyAttribute>
2683+ dunderGetItemNamed (const std::string &name) {
26812684 MlirAttribute attr = mlirOperationGetAttributeByName (operation->get (),
26822685 toMlirStringRef (name));
26832686 if (mlirAttributeIsNull (attr)) {
@@ -3461,7 +3464,7 @@ void mlir::python::populateIRCore(nb::module_ &m) {
34613464 " Returns the list of Operation results." )
34623465 .def_prop_ro (
34633466 " result" ,
3464- [](PyOperationBase &self) {
3467+ [](PyOperationBase &self) -> nb::typed<nb::object, PyOpResult> {
34653468 auto &operation = self.getOperation ();
34663469 return PyOpResult (operation.getRef (), getUniqueResult (operation))
34673470 .maybeDownCast ();
@@ -3982,7 +3985,8 @@ void mlir::python::populateIRCore(nb::module_ &m) {
39823985 .def (MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyAttribute::createFromCapsule)
39833986 .def_static (
39843987 " parse" ,
3985- [](const std::string &attrSpec, DefaultingPyMlirContext context) {
3988+ [](const std::string &attrSpec, DefaultingPyMlirContext context)
3989+ -> nb::typed<nb::object, PyAttribute> {
39863990 PyMlirContext::ErrorCapture errors (context->getRef ());
39873991 MlirAttribute attr = mlirAttributeParseGet (
39883992 context->get (), toMlirStringRef (attrSpec));
@@ -3998,7 +4002,7 @@ void mlir::python::populateIRCore(nb::module_ &m) {
39984002 [](PyAttribute &self) { return self.getContext ().getObject (); },
39994003 " Context that owns the Attribute" )
40004004 .def_prop_ro (" type" ,
4001- [](PyAttribute &self) {
4005+ [](PyAttribute &self) -> nb::typed<nb::object, PyType> {
40024006 return PyType (self.getContext (),
40034007 mlirAttributeGetType (self))
40044008 .maybeDownCast ();
@@ -4049,7 +4053,10 @@ void mlir::python::populateIRCore(nb::module_ &m) {
40494053 " mlirTypeID was expected to be non-null." );
40504054 return PyTypeID (mlirTypeID);
40514055 })
4052- .def (MLIR_PYTHON_MAYBE_DOWNCAST_ATTR, &PyAttribute::maybeDownCast);
4056+ .def (MLIR_PYTHON_MAYBE_DOWNCAST_ATTR,
4057+ [](PyAttribute &self) -> nb::typed<nb::object, PyAttribute> {
4058+ return self.maybeDownCast ();
4059+ });
40534060
40544061 // ----------------------------------------------------------------------------
40554062 // Mapping of PyNamedAttribute
@@ -4094,7 +4101,8 @@ void mlir::python::populateIRCore(nb::module_ &m) {
40944101 .def (MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyType::createFromCapsule)
40954102 .def_static (
40964103 " parse" ,
4097- [](std::string typeSpec, DefaultingPyMlirContext context) {
4104+ [](std::string typeSpec,
4105+ DefaultingPyMlirContext context) -> nb::typed<nb::object, PyType> {
40984106 PyMlirContext::ErrorCapture errors (context->getRef ());
40994107 MlirType type =
41004108 mlirTypeParseGet (context->get (), toMlirStringRef (typeSpec));
@@ -4139,7 +4147,10 @@ void mlir::python::populateIRCore(nb::module_ &m) {
41394147 printAccum.parts .append (" )" );
41404148 return printAccum.join ();
41414149 })
4142- .def (MLIR_PYTHON_MAYBE_DOWNCAST_ATTR, &PyType::maybeDownCast)
4150+ .def (MLIR_PYTHON_MAYBE_DOWNCAST_ATTR,
4151+ [](PyType &self) -> nb::typed<nb::object, PyType> {
4152+ return self.maybeDownCast ();
4153+ })
41434154 .def_prop_ro (" typeid" , [](PyType &self) {
41444155 MlirTypeID mlirTypeID = mlirTypeGetTypeID (self);
41454156 if (!mlirTypeIDIsNull (mlirTypeID))
@@ -4266,7 +4277,7 @@ void mlir::python::populateIRCore(nb::module_ &m) {
42664277 },
42674278 nb::arg (" state" ), kGetNameAsOperand )
42684279 .def_prop_ro (" type" ,
4269- [](PyValue &self) {
4280+ [](PyValue &self) -> nb::typed<nb::object, PyType> {
42704281 return PyType (self.getParentOperation ()->getContext (),
42714282 mlirValueGetType (self.get ()))
42724283 .maybeDownCast ();
@@ -4332,7 +4343,10 @@ void mlir::python::populateIRCore(nb::module_ &m) {
43324343 },
43334344 nb::arg (" with_" ), nb::arg (" exceptions" ),
43344345 kValueReplaceAllUsesExceptDocstring )
4335- .def (MLIR_PYTHON_MAYBE_DOWNCAST_ATTR, &PyValue::maybeDownCast)
4346+ .def (MLIR_PYTHON_MAYBE_DOWNCAST_ATTR,
4347+ [](PyValue &self) -> nb::typed<nb::object, PyValue> {
4348+ return self.maybeDownCast ();
4349+ })
43364350 .def_prop_ro (
43374351 " location" ,
43384352 [](MlirValue self) {
0 commit comments