Callback repr and "AttributeError: 'method-wrapper' object has no attribute '__code__' " (in v1)

Fastai version 1.0.54.

I’ve come across this error message a number of times:

AttributeError: 'method-wrapper' object has no attribute '__code__'

which originates from this line of code in callback.py

def  __repr__(self):
        attrs = func_args(self.__init__)  # <---
        ....

and at that time, self.__init__ does indeed have type 'method-wrapper

It is easy to reproduce this error. It seems to happen with any LearnerCallback:

from fastai import callbacks
learner = # some learner object
cb = callbacks.MixUpCallback(learner)
cb # attempt to print callback invokes __repr__ causing error

I don’t really grok what is happening in the LearnerCallback class, but I suspect that it is the LearnerCallback.__getattr__ method that is causing the wrapping, and hence the error. But this seems like a mainstream code path, so it should work usually, but how?

In any case is there a way to mitigate this issue? It comes up when debugging, if you attempt to print any callback, or anything that includes a callback in its representation.

You should upgrade to v1.0.57. I tried your code and didn’t have any problem so I’m guessing it has been solved since them.

Thanks!
Weirdly, I just restarted the 1.0.54 kernel, and the error didn’t happen. Which explains why I only sometimes see the error. But not what causes it in the first place.

If I get something that is reproducible from a clean kernel, I’ll let you know :slight_smile: