Parent classes cannot be reloaded
Opened this issue · 4 comments
Hello, I encounter the following error "TypeError: init() takes 2 positional arguments but 4 were given" whenever I import the classes in a package I'm coding.
I get the previous error whenever I define a Child class, which inherits form a decorated Parent Class using autoreload, regardless if the Child class is decorated or not.
In reality I would like to decorate both classes since in my project I'd be heavily adjusting both.
I was wondering if this is simply not possible, if it is a mistake on my part, or if its a fixable error?
I'm currently using reloadr-0.4.1 and python 3.8.2
Here is a simple example that reproduces the behavior.
from reloadr import autoreload
@autoreload
class Example_Parent():
def __init__(self, *args, **kwargs):
self.example_parent = "example parent"
class Example_Child(Example_Parent):
def __init__(self, *args, **kwargs):
super().__init__
self.example_child = "example child"
Hi Alex,
This behaviour is currently not supported:
When you use @reloadr
or @autoreload
on a class, the result that would be a reference to the class is in fact a callable object that will keep a reference to the instance.
Source: https://github.com/hoh/reloadr/blob/master/reloadr.py#L119
This works fine when reloadr is used on a child class, but does not support inheritance.
I renamed this issue as this is a behaviour I would like reloadr to support.
Here is a complete example that fails to work:
from time import sleep
from reloadr import reloadr
@reloadr
class Vehicle:
x = 0
y = 0
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def move(self, dx=0, dy=0):
self.x += dx
self.y += dy
class Car(Vehicle):
def position(self):
return 'Car on {} {}'.format(self.x, self.y)
car = Car(1000, 3000)
while True:
car.move(1, 1)
print(car.position())
sleep(0.5)
Car._reload()
Hi Hoh,
I run 01_manual_reload.py in the examples directory,error is as follows:
TypeError: class must be set to a class, not 'ClassReloadr' object
python-BaseException.
I am using python3.9 on the win10 platform,What is the cause of this error?
Hi @zhangyq73 , can you please create a separate issue for this ?