Skip to content

Commit

Permalink
Don't raise error for partial functions
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbern committed Jul 8, 2024
1 parent 98d9032 commit 1939e2a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions modal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`, "
Expand Down

0 comments on commit 1939e2a

Please sign in to comment.