def task(weight=1):
    """
    Used as a convenience decorator to be able to declare tasks for a TaskSet
    inline in the class. Example:

        class ForumPage(TaskSet):
            @task(100)
            def read_thread(self):
                pass

            @task(7)
            def create_thread(self):
                pass
    """

    def decorator_func(func):
        func.locust_task_weight = weight
        return func

    """
    Check if task was used without parentheses (not called), like this::
    
        @task
        def my_task()
            pass
    """
    if callable(weight):
        func = weight
        weight = 1
        return decorator_func(func)
    else:
        return decorator_func