from pyson.JsonSubTypes import JsonSubTypes, getSubTypes from pyson.JsonTypeInfo import JsonTypeInfo from pyson.JsonTypeInfo import Id,As import unittest @JsonSubTypes(['test.JsonSubTypesTest.B','test.JsonSubTypesTest.C','test.JsonSubTypesTest.D']) class A: pass class B(A): pass class C(B): pass class D(A): pass class JsonSubTypesTest(unittest.TestCase): def test1(self): @JsonSubTypes(["first.sub.class","subclss2"]) class superclass: def print(self, *args): for arg in args: print(arg) class derivedclass(superclass): pass print(type(superclass)) print(superclass.__jsonsubtypes__) pr = superclass() pr.print(1, 2, 3) print(type(pr)) print(pr.__jsonsubtypes__) print("checking __jsonsubtypes__ function") # WHY is self not added in this call??? print(superclass.__jsonsubtypes__) print(derivedclass.__jsonsubtypes__) class super2nojason: pass # even with mixedclass, we inherit the annotation class mixedclass(superclass, super2nojason): pass print(mixedclass.__jsonsubtypes__) @JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT) @JsonSubTypes(["Cat"]) class Animal: def __init__(self, age:int): self._age=age def getage(self): return self_age class Cat(Animal): def __init__(self, age:int, color:str): super().__init__(age) self._color=color def getcolor(self): return self._color cat=Cat(1,"brown") print(cat.__jsonsubtypes__) print(str(cat.__jsontypeinfo__)) def testInheritance(self): self.assertEqual({A,B,C,D} ,getSubTypes(A)) self.assertEqual({B,C} ,getSubTypes(B)) self.assertEqual({C} ,getSubTypes(C)) self.assertEqual({D} ,getSubTypes(D))