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

Classes with inheritance as main_callable will be called with the parent __init__, not the overriden one. #94

Closed
gregistech opened this issue Feb 11, 2024 · 3 comments

Comments

@gregistech
Copy link

gregistech commented Feb 11, 2024

Node:

from lazysocials.platforms import Twitter
from lazysocials.platforms.twitter import TwitterAuth

from lazycommon.content.types import Content

from typing import Type

main_callable = Twitter

def _Twitter(auth: TwitterAuth, max_images: {"widget_name": "int_float_entry", "widget_kwargs": {"min_value": 0, "max_value": 4}, "type": int} = 4, *types: Type[Content]) -> [{"name": "twitter", "type": Twitter}]:
        pass

signature_callable = _Twitter

Twitter:

class Twitter(Platform):
        def __init__(self, auth: TwitterAuth, max_images: int = 4, *types: Type[types.Content]):
                self._twitter_auth = auth
                self.max_images = max_images
                print(f"twitter: {types}")
                super().__init__(types)
# ...

# A chain of inheritance is formed with Platform

And the root init gets called, thus the signature is obv. incorrect and it fails.

(The first init only needs a list, while we get an int for in the Twitter class)

image

For now I can make a function that calls the init correctly, but Callable mode will not work that way obv. like so:

def _Twitter(auth: TwitterAuth, max_images: {"widget_name": "int_float_entry", "widget_kwargs": {"min_value": 0, "max_value": 4}, "type": int} = 4, *types: Type[Content]) -> [{"name": "twitter", "type": Twitter}]:
        return Twitter(auth, max_images, *types)

main_callable = _Twitter
@gregistech
Copy link
Author

Now that I've done that workaround I still get the same error, might be a problem on my end.

@gregistech
Copy link
Author

Yup, had an old init left around.

Check your code with bigger projects!

@KennedyRichard
Copy link
Collaborator

I was just about to ask for more info since I tried to replicate the problem on my end and didn't find any problems. I'm glad you pinpointed the problem.


Unrelated to your problem, but useful nonetheless (just a small tip): if you add the following line to your script, whenever you export a graph that contains this node the resulting Python code will import Twitter directly from lazysocials.platforms:

third_party_import_text = "from lazysocials.platforms import Twitter"

Exporting to Python will still work fine without it, so it is not mandatory. Without it, though, the resulting exported Python code will import the Twitter class from your node script rather than import it directly from lazysocials.platforms. Functionally, the end result is the same, but it is a bit more roundabout.

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

No branches or pull requests

2 participants