Skip to content

Commit 35593f6

Browse files
authored
[MLIR][Python] Use isinstance() instead of issubclass(type(...), ...) (#82345)
The two forms are equivalent, so there is no reason to use the longer one.
1 parent 48101ed commit 35593f6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

mlir/test/mlir-tblgen/op-python-bindings.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def AttributedOp : TestOp<"attributed_op"> {
123123
// CHECK: attributes = {}
124124
// CHECK: regions = None
125125
// CHECK: attributes["i32attr"] = (i32attr if (
126-
// CHECK-NEXT: issubclass(type(i32attr), _ods_ir.Attribute) or
126+
// CHECK-NEXT: isinstance(i32attr, _ods_ir.Attribute) or
127127
// CHECK-NEXT: not _ods_ir.AttrBuilder.contains('I32Attr')
128128
// CHECK-NEXT: _ods_ir.AttrBuilder.get('I32Attr')(i32attr, context=_ods_context)
129129
// CHECK: if optionalF32Attr is not None: attributes["optionalF32Attr"] = (optionalF32Attr

mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ constexpr const char *multiResultAppendTemplate = "results.extend({0})";
534534
/// there is no method registered to make it an Attribute.
535535
constexpr const char *initAttributeWithBuilderTemplate =
536536
R"Py(attributes["{1}"] = ({0} if (
537-
issubclass(type({0}), _ods_ir.Attribute) or
537+
isinstance({0}, _ods_ir.Attribute) or
538538
not _ods_ir.AttrBuilder.contains('{2}')) else
539539
_ods_ir.AttrBuilder.get('{2}')({0}, context=_ods_context)))Py";
540540

@@ -547,7 +547,7 @@ constexpr const char *initAttributeWithBuilderTemplate =
547547
/// there is no method registered to make it an Attribute.
548548
constexpr const char *initOptionalAttributeWithBuilderTemplate =
549549
R"Py(if {0} is not None: attributes["{1}"] = ({0} if (
550-
issubclass(type({0}), _ods_ir.Attribute) or
550+
isinstance({0}, _ods_ir.Attribute) or
551551
not _ods_ir.AttrBuilder.contains('{2}')) else
552552
_ods_ir.AttrBuilder.get('{2}')({0}, context=_ods_context)))Py";
553553

0 commit comments

Comments
 (0)