hoh/reloadr

error with reloading a subclass

doubleliang opened this issue · 1 comments

When using the following script:

import time
from reloadr import reloadr
class C:

    def __init__(self, name):
        print 'base C : ' + name


@reloadr
class Car(C):

    def __init__(self, name):
        super(Car, self).__init__(name)
        self.name = name
    def position(self):
        return self.name, 8

if __name__ == "__main__":

    print("Here we go")
    car = Car('t1')
    while True:
        print(car.position())
        time.sleep(1)
        Car._reload()

got this error when run the script:

 Traceback (most recent call last):
   File "<input>", line 1, in <module>
   File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
     pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
   File " reload_test.py", line 21, in <module>
    car = Car('t1')
  File "reloadr.py", line 108, in __call__
    instance = self._target.__call__(*args, **kwargs)
AttributeError: class Car has no attribute '__call__'
hoh commented

I could not reproduce the issue in the new version of reloadr (0.4.1) and after porting your code to Python 3 and running it on Python 3.6.

My version:

import time
from reloadr import reloadr


class C:
    def __init__(self, name):
        print('base C : ', name)


@reloadr
class Car(C):

    def __init__(self, name):
        super().__init__(name)
        self.name = name

    def position(self):
        return self.name, 1


if __name__ == "__main__":

    print("Here we go")
    car = Car('t1')
    while True:
        print(car.position())
        time.sleep(1)
        Car._reload()