[Mlir-commits] [mlir] [MLIR][Python] Register `OpAttributeMap` as `Mapping` for `match` compatibility (PR #174292)

Maksim Levental llvmlistbot at llvm.org
Fri Jan 9 17:59:24 PST 2026


================
@@ -1782,6 +1782,9 @@ class MLIR_PYTHON_API_EXPORTED PyOpAttributeMap {
 
   PyNamedAttribute dunderGetItemIndexed(intptr_t index);
 
+  nanobind::object getWithDefaultNamed(const std::string &key,
----------------
makslevental wrote:

> Sadly I also wrote a novel again

Don't worry I like reading novels :)

> But because of the default parameter this does not really hold true, because it could also return the default value, which might not be an Attribute?

But it's an AttributeMap right? If the user wants to subvert that by passing `default=Foo` where `Foo` isn't an attribute then that's on them... The generics options aren't possible yet because our min support version is 3.10 but what you can do if you want to handle `| None` (I believe) is just `nanobind::typed<nanobind::object, std::optional<PyAttribute>>` - I believe that will generate the signature `Attribute | None`. Let me double check.


https://github.com/llvm/llvm-project/pull/174292


More information about the Mlir-commits mailing list