@@ -161,25 +161,26 @@ ValueKind InferSequenceKind(const py::sequence& value) {
161161}
162162
163163ValueKind InferValueKind (
164- py::handle value, const std::optional<PyTunable::PythonType>& valueType,
165- const std::optional<PyTunable::PythonType>& elementType) {
166- if (valueType && elementType) {
164+ py::handle value,
165+ const py::typing::Optional<PyTunable::PythonType>& valueType,
166+ const py::typing::Optional<PyTunable::PythonType>& elementType) {
167+ if (!valueType.is_none () && !elementType.is_none ()) {
167168 throw py::type_error (" value_type and element_type are mutually exclusive" );
168169 }
169- if (elementType) {
170+ if (! elementType. is_none () ) {
170171 if (!IsSequenceValue (value)) {
171172 throw py::type_error (
172173 " element_type is only supported for tunable sequences" );
173174 }
174- return KindFromElementType (* elementType);
175+ return KindFromElementType (elementType);
175176 }
176- if (valueType) {
177+ if (! valueType. is_none () ) {
177178 if (IsSequenceValue (value)) {
178179 throw py::type_error (
179180 " value_type is only supported for scalar tunables; use "
180181 " element_type for sequences" );
181182 }
182- return KindFromScalarType (* valueType);
183+ return KindFromScalarType (valueType);
183184 }
184185 if (py::isinstance<py::bool_>(value)) {
185186 return ValueKind::BOOLEAN ;
@@ -210,8 +211,8 @@ ValueKind InferValueKind(
210211PyTunable::PyTunable (py::object value, std::optional<Getter> getter,
211212 std::optional<Setter> setter,
212213 std::optional<TuneCallback> onTune, bool robust,
213- bool isMutable, std::optional <PythonType> valueType,
214- std::optional <PythonType> elementType,
214+ bool isMutable, py::typing::Optional <PythonType> valueType,
215+ py::typing::Optional <PythonType> elementType,
215216 std::optional<Properties> properties,
216217 std::string typeString, bool alwaysGet, bool narrowScalar)
217218 : m_getter{std::move (getter)},
@@ -436,8 +437,8 @@ wpi::tunables::TunableConfig PyTunable::MakeConfig(
436437
437438PyTunable::TunableVariant PyTunable::MakeValue (
438439 py::handle value, bool robust, bool isMutable,
439- const std::optional <PythonType>& valueType,
440- const std::optional <PythonType>& elementType,
440+ const py::typing::Optional <PythonType>& valueType,
441+ const py::typing::Optional <PythonType>& elementType,
441442 const std::optional<Properties>& properties, std::string typeString,
442443 bool alwaysGet, bool narrowScalar) {
443444 auto kind = InferValueKind (value, valueType, elementType);
@@ -478,8 +479,8 @@ PyTunable::TunableVariant PyTunable::MakeValue(
478479 return wpi::tunables::TunableStringVector{
479480 value.cast <std::vector<std::string>>(), config};
480481 case ValueKind::STRUCT : {
481- py::type type = valueType && IsWpiStructType (* valueType)
482- ? py::reinterpret_borrow<py::type>(* valueType)
482+ py::type type = ! valueType. is_none () && IsWpiStructType (valueType)
483+ ? py::reinterpret_borrow<py::type>(valueType)
483484 : py::type::of (value);
484485 int isInstance = PyObject_IsInstance (value.ptr (), type.ptr ());
485486 if (isInstance < 0 ) {
@@ -496,8 +497,8 @@ PyTunable::TunableVariant PyTunable::MakeValue(
496497 }
497498 case ValueKind::STRUCT_ARRAY : {
498499 auto sequence = py::reinterpret_borrow<py::sequence>(value);
499- py::type type = elementType && IsWpiStructType (* elementType)
500- ? py::reinterpret_borrow<py::type>(* elementType)
500+ py::type type = ! elementType. is_none () && IsWpiStructType (elementType)
501+ ? py::reinterpret_borrow<py::type>(elementType)
501502 : GetStructSequenceType (sequence);
502503 ValidateStructSequenceType (sequence, type);
503504 WPyStructInfo info{type};
0 commit comments