fastai.fastcore patch decorator vs simpe monkey-patching

Viewed 34

I'm trying to understand the value-added of using fastai's fastcore.basics.patch_to decorator. Here's the fastcore way:

from fastcore.basics import patch_to


class _T3(int):
    pass


@patch_to(_T3)
def func1(self, a):
    return self + a

And here's the simple monkey-patching approach:

class simple_T3(int):
    pass


def func1(self, a):
    return self + a


simple_T3.func1 = func1

Inspecting the two classes does not reveal any differences. I understand that simple monkey-patching might cause problems in more complex cases, so it would be great to know what such cases are? In other words, what's the value-added of fastcore.basics.patch_to?

0 Answers
Related