Skip to content

Draft/RFC: Adds a Service mixin that can be used to get static type safety for classes #3077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

freider
Copy link
Contributor

@freider freider commented May 2, 2025

Very rough "implementation", just adding some static type check tests that this actually provides static type support.

This doesn't actually implement these methods, and it's a bit TBD if the actual implementation should be in in the mixin or the Obj (probably the latter?)

Preferably, the same implementation can be reused through composition in Function

This is also pending the discussion of whether to put these methods on the class directly or under a .service attribute or similar, but IMO this is the most promising and consistent way of doing it...


Check these boxes or delete any item (or this section) if not relevant for this PR.

  • Client+Server: this change is compatible with old servers
  • Client forward compatibility: this change ensures client can accept data intended for later versions of itself

Note on protobuf: protobuf message changes in one place may have impact to
multiple entities (client, server, worker, database). See points above.


Changelog

should_be_str = async_typed_func.remote(False) # should be blocking without aio
assert_type(should_be_str, str)


@app.cls()
class Cls:
class UserCls(modal.Service):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So beautiful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant