0

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 remove self from the function definition, but there is many lines like if self.a.b.c == True inside 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 function generate1()

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?

Tom Roth
  • 1,674
  • 15
  • 24
  • 1
    Copy pasting isn't ideal, but why didn't you copy paste the `self` argument as well if you just want to remove the decorator? – timgeb Sep 13 '21 at 05:12

0 Answers0