Skip to content

Commit eb00987

Browse files
committed
rig enum PyClass to be frozen
1 parent 44083b6 commit eb00987

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pyo3-macros-backend/src/pyclass.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,12 @@ fn impl_complex_enum(
765765
doc: PythonDoc,
766766
methods_type: PyClassMethodsType,
767767
) -> Result<TokenStream> {
768-
// Need to rig the enum PyClass to be subclassable by the variant PyClasses
768+
// Need to rig the enum PyClass options
769769
let args = {
770770
let mut rigged_args = args.clone();
771+
// Needs to be frozen to disallow `&mut self` methods, which could break a runtime invariant
772+
rigged_args.options.frozen = parse_quote!(frozen);
773+
// Needs to be subclassable by the variant PyClasses
771774
rigged_args.options.subclass = parse_quote!(subclass);
772775
rigged_args
773776
};
@@ -843,14 +846,10 @@ fn impl_complex_enum(
843846
};
844847
variant_cls_zsts.push(variant_cls_zst);
845848

846-
// TODO(mkovaxx): propagate variant.options
847-
let options: PyClassPyO3Options = parse_quote! {
848-
extends = #cls, frozen
849-
};
850-
851849
let variant_args = PyClassArgs {
852850
class_kind: PyClassKind::Struct,
853-
options,
851+
// TODO(mkovaxx): propagate variant.options
852+
options: parse_quote!(extends = #cls, frozen),
854853
deprecations: Deprecations::new(),
855854
};
856855

0 commit comments

Comments
 (0)