diff --git a/codegen/gen.py b/codegen/gen.py index 7541a6e9705..43dc296a317 100644 --- a/codegen/gen.py +++ b/codegen/gen.py @@ -134,15 +134,14 @@ def __call__(self, f: NativeFunction) -> str | None: if not self.selector.is_root_operator(f"{f.namespace}::{f.func.name}"): return None - if Variant.function not in f.variants and Variant.method in f.variants: - is_method_variant = True - - # only valid remaining case is only function is in f.variants - elif not (Variant.function in f.variants and Variant.method not in f.variants): + if Variant.function not in f.variants and Variant.method not in f.variants: raise Exception( # noqa: TRY002 - f"Can't handle native function {f.func} with the following variant specification {f.variants}." + f"Expected one of function or method to be in variants for {f.func.name}" ) + if Variant.function not in f.variants and Variant.method in f.variants: + is_method_variant = True + sig: CppSignature | ExecutorchCppSignature = ( CppSignatureGroup.from_native_function( f, method=False, fallback_binding=f.manual_cpp_binding