[Mlir-commits] [mlir] 35593f6 - [MLIR][Python] Use isinstance() instead of issubclass(type(...), ...) (#82345)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Feb 21 02:06:32 PST 2024
Author: Sergei Lebedev
Date: 2024-02-21T11:06:29+01:00
New Revision: 35593f6613445fe4a8daa6e7589deec82fcd4d2b
URL: https://github.com/llvm/llvm-project/commit/35593f6613445fe4a8daa6e7589deec82fcd4d2b
DIFF: https://github.com/llvm/llvm-project/commit/35593f6613445fe4a8daa6e7589deec82fcd4d2b.diff
LOG: [MLIR][Python] Use isinstance() instead of issubclass(type(...), ...) (#82345)
The two forms are equivalent, so there is no reason to use the longer
one.
Added:
Modified:
mlir/test/mlir-tblgen/op-python-bindings.td
mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
Removed:
################################################################################
diff --git a/mlir/test/mlir-tblgen/op-python-bindings.td b/mlir/test/mlir-tblgen/op-python-bindings.td
index f7df8ba2df0ae2..dbed1164f1eb0b 100644
--- a/mlir/test/mlir-tblgen/op-python-bindings.td
+++ b/mlir/test/mlir-tblgen/op-python-bindings.td
@@ -123,7 +123,7 @@ def AttributedOp : TestOp<"attributed_op"> {
// CHECK: attributes = {}
// CHECK: regions = None
// CHECK: attributes["i32attr"] = (i32attr if (
- // CHECK-NEXT: issubclass(type(i32attr), _ods_ir.Attribute) or
+ // CHECK-NEXT: isinstance(i32attr, _ods_ir.Attribute) or
// CHECK-NEXT: not _ods_ir.AttrBuilder.contains('I32Attr')
// CHECK-NEXT: _ods_ir.AttrBuilder.get('I32Attr')(i32attr, context=_ods_context)
// CHECK: if optionalF32Attr is not None: attributes["optionalF32Attr"] = (optionalF32Attr
diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
index 0770ed562309e7..640360eff734a6 100644
--- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
@@ -534,7 +534,7 @@ constexpr const char *multiResultAppendTemplate = "results.extend({0})";
/// there is no method registered to make it an Attribute.
constexpr const char *initAttributeWithBuilderTemplate =
R"Py(attributes["{1}"] = ({0} if (
- issubclass(type({0}), _ods_ir.Attribute) or
+ isinstance({0}, _ods_ir.Attribute) or
not _ods_ir.AttrBuilder.contains('{2}')) else
_ods_ir.AttrBuilder.get('{2}')({0}, context=_ods_context)))Py";
@@ -547,7 +547,7 @@ constexpr const char *initAttributeWithBuilderTemplate =
/// there is no method registered to make it an Attribute.
constexpr const char *initOptionalAttributeWithBuilderTemplate =
R"Py(if {0} is not None: attributes["{1}"] = ({0} if (
- issubclass(type({0}), _ods_ir.Attribute) or
+ isinstance({0}, _ods_ir.Attribute) or
not _ods_ir.AttrBuilder.contains('{2}')) else
_ods_ir.AttrBuilder.get('{2}')({0}, context=_ods_context)))Py";
More information about the Mlir-commits
mailing list