From 987613bc34d42adccc90ad2bca186d63ca674f71 Mon Sep 17 00:00:00 2001 From: Erik Bernhardsson Date: Mon, 8 Jul 2024 14:26:07 +0000 Subject: [PATCH] Don't raise error for partial functions --- modal/app.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/modal/app.py b/modal/app.py index cd945ac6d..c744ad67a 100644 --- a/modal/app.py +++ b/modal/app.py @@ -537,24 +537,6 @@ def wrapped( "The `@app.function` decorator cannot be used on a class. Please use `@app.cls` instead." ) - if not is_top_level_function(f) and not serialized: - raise InvalidError( - dedent( - """ - The `@app.function` decorator cannot be used on class methods. - Please use `@app.cls` with `@modal.method` instead. Example: - - ```python - @app.cls() - class MyClass: - @method() - def f(self, x): - ... - ``` - """ - ) - ) - if isinstance(f, _PartialFunction): # typically for @function-wrapped @web_endpoint and @asgi_app f.wrapped = True @@ -571,6 +553,24 @@ def f(self, x): webhook_config = None raw_f = f + if not is_top_level_function(f) and not serialized: + raise InvalidError( + dedent( + """ + The `@app.function` decorator cannot be used on class methods. + Please use `@app.cls` with `@modal.method` instead. Example: + + ```python + @app.cls() + class MyClass: + @method() + def f(self, x): + ... + ``` + """ + ) + ) + if info.function_name.endswith(".app"): warnings.warn( "Beware: the function name is `app`. Modal will soon rename `Stub` to `App`, "