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

Implement serialization of subclasses #76

Open
braxtonmckee opened this issue Jan 29, 2020 · 0 comments
Open

Implement serialization of subclasses #76

braxtonmckee opened this issue Jan 29, 2020 · 0 comments

Comments

@braxtonmckee
Copy link
Contributor

this should work but doesn't, because we don't have a pathway for serializing a subclass of a Class instance where we know the type as the base class. In the below case, we know that a ListOf(C) contains C pointers, and we can stick a 'Subclass' pointer in it. If we serialize the objects individually, the interpreter will dispatch to the Subclass serialize method. But if we serialize the list itself, we end up dispatching to 'C''s serialization routine, which can't handle the child class.

    def test_serialize_subclasses(self):
        class C(Class):
            pass

        class Subclass(C, Final):
            def f(self):
                return 10

        sc = SerializationContext({'Subclass': Subclass, 'C': C})

        listOfClassObjects = ListOf(C)()
        listOfClassObjects.append(Subclass())

        instOfSubclass = sc.deserialize(sc.serialize(listOfClassObjects))[0]

        self.assertIsInstance(instOfSubclass, Subclass)
        self.assertEqual(instOfSubclass.f(), 10)
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

1 participant