fastai / fastcore

Python supercharged for the fastai library
http://fastcore.fast.ai
Apache License 2.0
973 stars 276 forks source link

Cant directly use `@patch_to` to redefine a class constructor #520

Closed diego898 closed 1 year ago

diego898 commented 1 year ago
class A():
    def __init__(self):
        super().__init__()
        print('hi')

A()

@patch_to(A)
def __init__(self):
    super().__init__()
    print('hello')

A()

returns RuntimeError: super(): __class__ cell not found.

Is it worth adding to the docs that this is the case?

JunnYu commented 1 year ago
class A():
    def __init__(self):
        super().__init__()
        print('hi')

A()

@patch_to(A)
def __init__(self):
    super(A, self).__init__()
    print('hello')

A()