I'm using a python package called transformers. This package is complicated and has lots of classes that inherit from each other.
I'm using an instance (lets call it model) of one particular class (let's call it Model). There is a class method model.generate() that is useful, but
I would like to change one line of this method generate() (specifically, to remove its decorator).
I have tried defining a function generate1() and copy-pasting the code of model.generate() into generate1(), and then executing model.generate1 = generate1(). Unfortunately I run into some problems
- the error
generate1() missing 1 required positional argument: 'self'. I could removeselffrom the function definition, but there is many lines likeif self.a.b.c == Trueinside the function, so it's not easy to change all of those lines too. - there are also many missing imports. These are defined in the body of the classes of
transformers, but not in my functiongenerate1()
The easiest way seems to be changing the source code of the package directly, but if I update the package I might lose the changes, so a bit reluctant to do this.
Is there an easier way?