Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 68f631a

Browse files
authored
[MLIR][Python] remove unnecessary arg.none() = nb::none() pattern (#157519)
We have `arg.none() = nb::none()` in a lot of places but this is no longer necessary (as of ~[2022](wjakob/nanobind@62a23bb)).
1 parent d269268 commit 68f631a

File tree

13 files changed

+156
-178
lines changed

13 files changed

+156
-178
lines changed

mlir/lib/Bindings/Python/DialectGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ NB_MODULE(_mlirDialectsGPU, m) {
3838
return cls(mlirGPUAsyncTokenTypeGet(ctx));
3939
},
4040
"Gets an instance of AsyncTokenType in the same context", nb::arg("cls"),
41-
nb::arg("ctx").none() = nb::none());
41+
nb::arg("ctx") = nb::none());
4242

4343
//===-------------------------------------------------------------------===//
4444
// ObjectAttr
@@ -62,7 +62,7 @@ NB_MODULE(_mlirDialectsGPU, m) {
6262
: MlirAttribute{nullptr}));
6363
},
6464
"cls"_a, "target"_a, "format"_a, "object"_a,
65-
"properties"_a.none() = nb::none(), "kernels"_a.none() = nb::none(),
65+
"properties"_a = nb::none(), "kernels"_a = nb::none(),
6666
"Gets a gpu.object from parameters.")
6767
.def_property_readonly(
6868
"target",

mlir/lib/Bindings/Python/DialectLLVM.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
4747
return cls(type);
4848
},
4949
"cls"_a, "elements"_a, nb::kw_only(), "packed"_a = false,
50-
"loc"_a.none() = nb::none());
50+
"loc"_a = nb::none());
5151

5252
llvmStructType.def_classmethod(
5353
"get_identified",
5454
[](const nb::object &cls, const std::string &name, MlirContext context) {
5555
return cls(mlirLLVMStructTypeIdentifiedGet(
5656
context, mlirStringRefCreate(name.data(), name.size())));
5757
},
58-
"cls"_a, "name"_a, nb::kw_only(), "context"_a.none() = nb::none());
58+
"cls"_a, "name"_a, nb::kw_only(), "context"_a = nb::none());
5959

6060
llvmStructType.def_classmethod(
6161
"get_opaque",
6262
[](const nb::object &cls, const std::string &name, MlirContext context) {
6363
return cls(mlirLLVMStructTypeOpaqueGet(
6464
context, mlirStringRefCreate(name.data(), name.size())));
6565
},
66-
"cls"_a, "name"_a, "context"_a.none() = nb::none());
66+
"cls"_a, "name"_a, "context"_a = nb::none());
6767

6868
llvmStructType.def(
6969
"set_body",
@@ -86,7 +86,7 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
8686
elements.size(), elements.data(), packed));
8787
},
8888
"cls"_a, "name"_a, "elements"_a, nb::kw_only(), "packed"_a = false,
89-
"context"_a.none() = nb::none());
89+
"context"_a = nb::none());
9090

9191
llvmStructType.def_property_readonly(
9292
"name", [](MlirType type) -> std::optional<std::string> {
@@ -133,8 +133,8 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
133133
}
134134
return cls(type);
135135
},
136-
"cls"_a, "address_space"_a.none() = nb::none(), nb::kw_only(),
137-
"context"_a.none() = nb::none())
136+
"cls"_a, "address_space"_a = nb::none(), nb::kw_only(),
137+
"context"_a = nb::none())
138138
.def_property_readonly("address_space", [](MlirType type) {
139139
return mlirLLVMPointerTypeGetAddressSpace(type);
140140
});

mlir/lib/Bindings/Python/DialectNVGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void populateDialectNVGPUSubmodule(const nb::module_ &m) {
3131
"Gets an instance of TensorMapDescriptorType in the same context",
3232
nb::arg("cls"), nb::arg("tensor_type"), nb::arg("swizzle"),
3333
nb::arg("l2promo"), nb::arg("oob_fill"), nb::arg("interleave"),
34-
nb::arg("ctx").none() = nb::none());
34+
nb::arg("ctx") = nb::none());
3535
}
3636

3737
NB_MODULE(_mlirDialectsNVGPU, m) {

mlir/lib/Bindings/Python/DialectPDL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
3636
return cls(mlirPDLAttributeTypeGet(ctx));
3737
},
3838
"Get an instance of AttributeType in given context.", nb::arg("cls"),
39-
nb::arg("context").none() = nb::none());
39+
nb::arg("context") = nb::none());
4040

4141
//===-------------------------------------------------------------------===//
4242
// OperationType
@@ -50,7 +50,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
5050
return cls(mlirPDLOperationTypeGet(ctx));
5151
},
5252
"Get an instance of OperationType in given context.", nb::arg("cls"),
53-
nb::arg("context").none() = nb::none());
53+
nb::arg("context") = nb::none());
5454

5555
//===-------------------------------------------------------------------===//
5656
// RangeType
@@ -81,7 +81,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
8181
return cls(mlirPDLTypeTypeGet(ctx));
8282
},
8383
"Get an instance of TypeType in given context.", nb::arg("cls"),
84-
nb::arg("context").none() = nb::none());
84+
nb::arg("context") = nb::none());
8585

8686
//===-------------------------------------------------------------------===//
8787
// ValueType
@@ -94,7 +94,7 @@ static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
9494
return cls(mlirPDLValueTypeGet(ctx));
9595
},
9696
"Get an instance of TypeType in given context.", nb::arg("cls"),
97-
nb::arg("context").none() = nb::none());
97+
nb::arg("context") = nb::none());
9898
}
9999

100100
NB_MODULE(_mlirDialectsPDL, m) {

mlir/lib/Bindings/Python/DialectSMT.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ static void populateDialectSMTSubmodule(nanobind::module_ &m) {
3232
[](const nb::object &, MlirContext context) {
3333
return mlirSMTTypeGetBool(context);
3434
},
35-
"cls"_a, "context"_a.none() = nb::none());
35+
"cls"_a, "context"_a = nb::none());
3636
auto smtBitVectorType =
3737
mlir_type_subclass(m, "BitVectorType", mlirSMTTypeIsABitVector)
3838
.def_classmethod(
3939
"get",
4040
[](const nb::object &, int32_t width, MlirContext context) {
4141
return mlirSMTTypeGetBitVector(context, width);
4242
},
43-
"cls"_a, "width"_a, "context"_a.none() = nb::none());
43+
"cls"_a, "width"_a, "context"_a = nb::none());
4444

4545
auto exportSMTLIB = [](MlirOperation module, bool inlineSingleUseValues,
4646
bool indentLetBody) {

mlir/lib/Bindings/Python/DialectSparseTensor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ static void populateDialectSparseTensorSubmodule(const nb::module_ &m) {
5353
},
5454
nb::arg("cls"), nb::arg("lvl_types"), nb::arg("dim_to_lvl").none(),
5555
nb::arg("lvl_to_dim").none(), nb::arg("pos_width"),
56-
nb::arg("crd_width"), nb::arg("explicit_val").none() = nb::none(),
57-
nb::arg("implicit_val").none() = nb::none(),
58-
nb::arg("context").none() = nb::none(),
56+
nb::arg("crd_width"), nb::arg("explicit_val") = nb::none(),
57+
nb::arg("implicit_val") = nb::none(), nb::arg("context") = nb::none(),
5958
"Gets a sparse_tensor.encoding from parameters.")
6059
.def_classmethod(
6160
"build_level_type",

mlir/lib/Bindings/Python/DialectTransform.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
3333
return cls(mlirTransformAnyOpTypeGet(ctx));
3434
},
3535
"Get an instance of AnyOpType in the given context.", nb::arg("cls"),
36-
nb::arg("context").none() = nb::none());
36+
nb::arg("context") = nb::none());
3737

3838
//===-------------------------------------------------------------------===//
3939
// AnyParamType
@@ -48,7 +48,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
4848
return cls(mlirTransformAnyParamTypeGet(ctx));
4949
},
5050
"Get an instance of AnyParamType in the given context.", nb::arg("cls"),
51-
nb::arg("context").none() = nb::none());
51+
nb::arg("context") = nb::none());
5252

5353
//===-------------------------------------------------------------------===//
5454
// AnyValueType
@@ -63,7 +63,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
6363
return cls(mlirTransformAnyValueTypeGet(ctx));
6464
},
6565
"Get an instance of AnyValueType in the given context.", nb::arg("cls"),
66-
nb::arg("context").none() = nb::none());
66+
nb::arg("context") = nb::none());
6767

6868
//===-------------------------------------------------------------------===//
6969
// OperationType
@@ -83,7 +83,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
8383
"Get an instance of OperationType for the given kind in the given "
8484
"context",
8585
nb::arg("cls"), nb::arg("operation_name"),
86-
nb::arg("context").none() = nb::none());
86+
nb::arg("context") = nb::none());
8787
operationType.def_property_readonly(
8888
"operation_name",
8989
[](MlirType type) {
@@ -106,7 +106,7 @@ static void populateDialectTransformSubmodule(const nb::module_ &m) {
106106
return cls(mlirTransformParamTypeGet(ctx, type));
107107
},
108108
"Get an instance of ParamType for the given type in the given context.",
109-
nb::arg("cls"), nb::arg("type"), nb::arg("context").none() = nb::none());
109+
nb::arg("cls"), nb::arg("type"), nb::arg("context") = nb::none());
110110
paramType.def_property_readonly(
111111
"type",
112112
[](MlirType type) {

mlir/lib/Bindings/Python/IRAffine.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class PyAffineConstantExpr : public PyConcreteAffineExpr<PyAffineConstantExpr> {
142142

143143
static void bindDerived(ClassTy &c) {
144144
c.def_static("get", &PyAffineConstantExpr::get, nb::arg("value"),
145-
nb::arg("context").none() = nb::none());
145+
nb::arg("context") = nb::none());
146146
c.def_prop_ro("value", [](PyAffineConstantExpr &self) {
147147
return mlirAffineConstantExprGetValue(self);
148148
});
@@ -162,7 +162,7 @@ class PyAffineDimExpr : public PyConcreteAffineExpr<PyAffineDimExpr> {
162162

163163
static void bindDerived(ClassTy &c) {
164164
c.def_static("get", &PyAffineDimExpr::get, nb::arg("position"),
165-
nb::arg("context").none() = nb::none());
165+
nb::arg("context") = nb::none());
166166
c.def_prop_ro("position", [](PyAffineDimExpr &self) {
167167
return mlirAffineDimExprGetPosition(self);
168168
});
@@ -182,7 +182,7 @@ class PyAffineSymbolExpr : public PyConcreteAffineExpr<PyAffineSymbolExpr> {
182182

183183
static void bindDerived(ClassTy &c) {
184184
c.def_static("get", &PyAffineSymbolExpr::get, nb::arg("position"),
185-
nb::arg("context").none() = nb::none());
185+
nb::arg("context") = nb::none());
186186
c.def_prop_ro("position", [](PyAffineSymbolExpr &self) {
187187
return mlirAffineSymbolExprGetPosition(self);
188188
});
@@ -588,7 +588,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
588588
self.getContext(),
589589
mlirAffineExprShiftDims(self, numDims, shift, offset));
590590
},
591-
nb::arg("num_dims"), nb::arg("shift"), nb::arg("offset").none() = 0)
591+
nb::arg("num_dims"), nb::arg("shift"), nb::arg("offset") = 0)
592592
.def(
593593
"shift_symbols",
594594
[](PyAffineExpr &self, uint32_t numSymbols, uint32_t shift,
@@ -597,8 +597,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
597597
self.getContext(),
598598
mlirAffineExprShiftSymbols(self, numSymbols, shift, offset));
599599
},
600-
nb::arg("num_symbols"), nb::arg("shift"),
601-
nb::arg("offset").none() = 0)
600+
nb::arg("num_symbols"), nb::arg("shift"), nb::arg("offset") = 0)
602601
.def_static(
603602
"simplify_affine_expr",
604603
[](PyAffineExpr &self, uint32_t numDims, uint32_t numSymbols) {
@@ -655,15 +654,15 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
655654
"Gets an affine expression containing the rounded-up result "
656655
"of dividing an expression by a constant.")
657656
.def_static("get_constant", &PyAffineConstantExpr::get, nb::arg("value"),
658-
nb::arg("context").none() = nb::none(),
657+
nb::arg("context") = nb::none(),
659658
"Gets a constant affine expression with the given value.")
660659
.def_static(
661660
"get_dim", &PyAffineDimExpr::get, nb::arg("position"),
662-
nb::arg("context").none() = nb::none(),
661+
nb::arg("context") = nb::none(),
663662
"Gets an affine expression of a dimension at the given position.")
664663
.def_static(
665664
"get_symbol", &PyAffineSymbolExpr::get, nb::arg("position"),
666-
nb::arg("context").none() = nb::none(),
665+
nb::arg("context") = nb::none(),
667666
"Gets an affine expression of a symbol at the given position.")
668667
.def(
669668
"dump", [](PyAffineExpr &self) { mlirAffineExprDump(self); },
@@ -746,7 +745,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
746745
return PyAffineMap(context->getRef(), map);
747746
},
748747
nb::arg("dim_count"), nb::arg("symbol_count"), nb::arg("exprs"),
749-
nb::arg("context").none() = nb::none(),
748+
nb::arg("context") = nb::none(),
750749
"Gets a map with the given expressions as results.")
751750
.def_static(
752751
"get_constant",
@@ -755,23 +754,23 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
755754
mlirAffineMapConstantGet(context->get(), value);
756755
return PyAffineMap(context->getRef(), affineMap);
757756
},
758-
nb::arg("value"), nb::arg("context").none() = nb::none(),
757+
nb::arg("value"), nb::arg("context") = nb::none(),
759758
"Gets an affine map with a single constant result")
760759
.def_static(
761760
"get_empty",
762761
[](DefaultingPyMlirContext context) {
763762
MlirAffineMap affineMap = mlirAffineMapEmptyGet(context->get());
764763
return PyAffineMap(context->getRef(), affineMap);
765764
},
766-
nb::arg("context").none() = nb::none(), "Gets an empty affine map.")
765+
nb::arg("context") = nb::none(), "Gets an empty affine map.")
767766
.def_static(
768767
"get_identity",
769768
[](intptr_t nDims, DefaultingPyMlirContext context) {
770769
MlirAffineMap affineMap =
771770
mlirAffineMapMultiDimIdentityGet(context->get(), nDims);
772771
return PyAffineMap(context->getRef(), affineMap);
773772
},
774-
nb::arg("n_dims"), nb::arg("context").none() = nb::none(),
773+
nb::arg("n_dims"), nb::arg("context") = nb::none(),
775774
"Gets an identity map with the given number of dimensions.")
776775
.def_static(
777776
"get_minor_identity",
@@ -782,7 +781,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
782781
return PyAffineMap(context->getRef(), affineMap);
783782
},
784783
nb::arg("n_dims"), nb::arg("n_results"),
785-
nb::arg("context").none() = nb::none(),
784+
nb::arg("context") = nb::none(),
786785
"Gets a minor identity map with the given number of dimensions and "
787786
"results.")
788787
.def_static(
@@ -796,7 +795,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
796795
context->get(), permutation.size(), permutation.data());
797796
return PyAffineMap(context->getRef(), affineMap);
798797
},
799-
nb::arg("permutation"), nb::arg("context").none() = nb::none(),
798+
nb::arg("permutation"), nb::arg("context") = nb::none(),
800799
"Gets an affine map that permutes its inputs.")
801800
.def(
802801
"get_submap",
@@ -923,7 +922,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
923922
return PyIntegerSet(context->getRef(), set);
924923
},
925924
nb::arg("num_dims"), nb::arg("num_symbols"), nb::arg("exprs"),
926-
nb::arg("eq_flags"), nb::arg("context").none() = nb::none())
925+
nb::arg("eq_flags"), nb::arg("context") = nb::none())
927926
.def_static(
928927
"get_empty",
929928
[](intptr_t numDims, intptr_t numSymbols,
@@ -933,7 +932,7 @@ void mlir::python::populateIRAffine(nb::module_ &m) {
933932
return PyIntegerSet(context->getRef(), set);
934933
},
935934
nb::arg("num_dims"), nb::arg("num_symbols"),
936-
nb::arg("context").none() = nb::none())
935+
nb::arg("context") = nb::none())
937936
.def(
938937
"get_replaced",
939938
[](PyIntegerSet &self, const nb::list &dimExprs,

0 commit comments

Comments
 (0)