Skip to content

Commit c8bcde9

Browse files
committed
fmt
1 parent 3e0a6d2 commit c8bcde9

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

pyo3-macros-backend/src/pyclass.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,9 +1109,10 @@ fn impl_complex_enum_tuple_variant_len(
11091109
}
11101110
};
11111111

1112-
let mut len_method_impl : syn ::ImplItemFn = syn::parse2(len_method_impl).unwrap();
1112+
let mut len_method_impl: syn::ImplItemFn = syn::parse2(len_method_impl).unwrap();
11131113

1114-
let variant_len = crate::pymethod::impl_py_slot_def(&variant_cls_type, ctx, &mut len_method_impl.sig)?;
1114+
let variant_len =
1115+
crate::pymethod::impl_py_slot_def(&variant_cls_type, ctx, &mut len_method_impl.sig)?;
11151116

11161117
Ok((variant_len, len_method_impl))
11171118
}
@@ -1138,23 +1139,23 @@ fn impl_complex_enum_tuple_variant_getitem(
11381139
})
11391140
.collect();
11401141

1141-
let matcher =
1142-
quote! {
1143-
let py = slf.py();
1144-
match idx {
1145-
#( #match_arms, )*
1146-
_ => Err(pyo3::exceptions::PyIndexError::new_err("tuple index out of range")),
1147-
}
1148-
};
1142+
let matcher = quote! {
1143+
let py = slf.py();
1144+
match idx {
1145+
#( #match_arms, )*
1146+
_ => Err(pyo3::exceptions::PyIndexError::new_err("tuple index out of range")),
1147+
}
1148+
};
11491149

11501150
let get_item_method_impl = quote! {
11511151
fn __getitem__(slf: #pyo3_path::PyRef<Self>, idx: usize) -> #pyo3_path::PyResult< #pyo3_path::PyObject> {
11521152
#matcher
11531153
}
11541154
};
11551155

1156-
let mut get_item_method_impl : syn ::ImplItemFn = syn::parse2(get_item_method_impl).unwrap();
1157-
let variant_getitem = crate::pymethod::impl_py_slot_def(&variant_cls_type, ctx, &mut get_item_method_impl.sig)?;
1156+
let mut get_item_method_impl: syn::ImplItemFn = syn::parse2(get_item_method_impl).unwrap();
1157+
let variant_getitem =
1158+
crate::pymethod::impl_py_slot_def(&variant_cls_type, ctx, &mut get_item_method_impl.sig)?;
11581159

11591160
Ok((variant_getitem, get_item_method_impl))
11601161
}
@@ -1187,20 +1188,13 @@ fn impl_complex_enum_tuple_variant_cls(
11871188

11881189
let num_fields = variant.fields.len();
11891190

1190-
let (variant_len, len_method_impl) = impl_complex_enum_tuple_variant_len(
1191-
ctx,
1192-
&variant_cls_type,
1193-
num_fields,
1194-
)?;
1191+
let (variant_len, len_method_impl) =
1192+
impl_complex_enum_tuple_variant_len(ctx, &variant_cls_type, num_fields)?;
11951193

11961194
slots.push(variant_len);
11971195

1198-
let (variant_getitem, getitem_method_impl) = impl_complex_enum_tuple_variant_getitem(
1199-
ctx,
1200-
&variant_cls,
1201-
&variant_cls_type,
1202-
num_fields,
1203-
)?;
1196+
let (variant_getitem, getitem_method_impl) =
1197+
impl_complex_enum_tuple_variant_getitem(ctx, &variant_cls, &variant_cls_type, num_fields)?;
12041198

12051199
slots.push(variant_getitem);
12061200

@@ -1415,12 +1409,10 @@ fn complex_enum_tuple_variant_new<'a>(
14151409
let _attrs =
14161410
crate::pyfunction::PyFunctionArgPyO3Attributes::from_attrs(&mut no_pyo3_attrs)?;
14171411

1418-
let mut args = vec![
1419-
FnArg::Py(PyArg {
1420-
name: &arg_py_ident,
1421-
ty: &arg_py_type,
1422-
}),
1423-
];
1412+
let mut args = vec![FnArg::Py(PyArg {
1413+
name: &arg_py_ident,
1414+
ty: &arg_py_type,
1415+
})];
14241416

14251417
for (i, field) in variant.fields.iter().enumerate() {
14261418
// TODO : Tracking issue for Cow in FnArg : #4156

pyo3-macros-backend/src/pymethod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,11 @@ fn impl_call_getter(
735735
Ok(fncall)
736736
}
737737

738-
739738
pub fn impl_py_slot_def(
740739
cls: &syn::Type,
741740
ctx: &Ctx,
742-
signature: &mut syn::Signature
741+
signature: &mut syn::Signature,
743742
) -> Result<MethodAndSlotDef> {
744-
745743
let spec = FnSpec::parse(
746744
signature,
747745
&mut Vec::new(),
@@ -755,13 +753,13 @@ pub fn impl_py_slot_def(
755753
PyMethodKind::Proto(proto_kind) => {
756754
ensure_no_forbidden_protocol_attributes(&proto_kind, &spec, &method_name)?;
757755
match proto_kind {
758-
PyMethodProtoKind::Slot(slot_def) => {
759-
slot_def
756+
PyMethodProtoKind::Slot(slot_def) => slot_def,
757+
_ => {
758+
bail_spanned!(signature.span() => "Only slot methods are supported in #[pyslot]")
760759
}
761-
_ => bail_spanned!(signature.span() => "Only slot methods are supported in #[pyslot]"),
762760
}
763-
},
764-
_ => bail_spanned!(signature.span() => "Only slot methods are supported in #[pyslot]"),
761+
}
762+
_ => bail_spanned!(signature.span() => "Only slot methods are supported in #[pyslot]"),
765763
};
766764

767765
Ok(slot.generate_type_slot(&cls, &spec, &method_name, ctx)?)

pytests/src/enums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub enum MixedComplexEnum {
8888
#[pyfunction]
8989
pub fn do_mixed_complex_stuff(thing: &MixedComplexEnum) -> MixedComplexEnum {
9090
match thing {
91-
MixedComplexEnum::Nothing {} => MixedComplexEnum::Empty (),
92-
MixedComplexEnum::Empty() => MixedComplexEnum::Nothing{},
91+
MixedComplexEnum::Nothing {} => MixedComplexEnum::Empty(),
92+
MixedComplexEnum::Empty() => MixedComplexEnum::Nothing {},
9393
}
9494
}

0 commit comments

Comments
 (0)