Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parent classes cannot be reloaded #9

Open
AlexVillarra opened this issue May 11, 2020 · 4 comments
Open

Parent classes cannot be reloaded #9

AlexVillarra opened this issue May 11, 2020 · 4 comments

Comments

@AlexVillarra
Copy link

AlexVillarra commented May 11, 2020

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"
@hoh
Copy link
Owner

hoh commented May 19, 2020

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.

@hoh hoh changed the title TypeError: __init__() when using super().__init__ on a child class Parent classes cannot be reloaded May 19, 2020
@hoh
Copy link
Owner

hoh commented May 19, 2020

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()

@zhangyq73
Copy link

zhangyq73 commented Apr 28, 2021

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?

@hoh
Copy link
Owner

hoh commented Apr 29, 2021

Hi @zhangyq73 , can you please create a separate issue for this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants