Add decorator hint to default comment in Server modules

I mean - I think this is overkill… one of the first things I do, whenever I open a new module, is delete the comments…

For new users that seems too much to me. Especially since they might not have met decorators yet…
IMO those comments should be enough to get started.
Perhaps a better place would be to add them to the docs in the advanced section…

Which is linked whenever you click the top level of the server module…

Screen Shot 2020-04-28 at 08.07.48


As a note I also prefer using

from functools import wraps

on my server wrappers.
This way the name is preserved without having to pass an argument to @anvil.server.callable

Your example would become:

from functools import wraps
def admin(func):
  @wraps
  def wrapper(*args, **kwargs):
      if not anvil.users.get_user()['admin']:
        return
      else:
        return (func(*args, **kwargs))
  return wrapper

# no need to tell callable what the name is. @wraps preserves it
@anvil.server.callable 
@admin
def say_hello(name):
  print("Hello, " + name + "!")
  return 42

hidden away at the bottom of the link you posted

2 Likes