by babyshake · 2y ago · 0 comments
Instead of this:
@ai() def describe(animals: list[str]) -> str: """ Given a list of animals, use one word that'd describe them all. """
it would seem a lot more intuitive to do this:
def describe(animals: list[str]) -> str: return ai("""Given a list of animals, use one word that'd describe them all.""", animals)
def foo():
4
Which is also an expression statement as a function body, and also does nothing. Contrast to actually using a comment as a function body; comments aren't statements (nor expressions, so they can't be used as an expression statement): def foo():
# this doesn't work
> IndentationError: expected an indented block after function definition on line 1Of course, this doesn't really matter at all, and I get that it feels strange. I've just been thinking about grammars and syntax lately, and it's been interesting to now have the vocabulary and mental model to understand these unintuitive things :)
@ai()
def describe(animals: list[str]) -> str:
""" Given a list of animals, use one word that'd describe them all. """
...For your suggestion, the decorator would still be required to overload the function execution with the remote call, otherwise you'd just be calling the function body, but we have considered special wrapper return types to help play better with pyright (and also give programmatic access to debug details of the call), but that'd add bloat to the package and subtract from the more native python feel we're aiming for.
Python has an existing convention for this (so its not a "trick"), the use of the special value Ellipsis (literal: ...)
@ai()
def stub() -> int:
"""docstring"""
...
# (use ... instead of "pass" in the function body)