Documentation breaks when I use a python decorator

Let’s see the popular example from Part 2 of the course, with the annealer decorator. We have the following function:

def annealer(f):
    def _inner(start, end):
        return partial(f, start, end)
    return _inner

Then I want to decorate a function with the annealer, so:

@annealer
def linear_scheduler(start, end, position):
    return start + position * (end - start)

But when I build the documentation I get the following result with an example:

Also, the table of contents displays it like this:

image

Is this a bug or is there something eluding me?

1 Like

You should either have your decorator fix the function name in the signature (look at the fastcore decorators for inspiration) or you can write the show_doc cell yourself and use the name argument to pass the name you want:

show_doc(linear_scheduler, name="linear_scheduler")
2 Likes

@sgugger Could you give an example of how to have my decorator fix the function name, or where to look in fastcore exactly?

Thanks a lot!

Like I said, look at the decorators defined in fastcore. I think the important line is

functools.update_wrapper(_f, old_f)