diff --git a/implementations/python/preserves/schema.py b/implementations/python/preserves/schema.py index e6d0d5d..37625b6 100644 --- a/implementations/python/preserves/schema.py +++ b/implementations/python/preserves/schema.py @@ -360,6 +360,10 @@ class Compiler: c._set_schema(self.root, module_path, n, d, None, None) ns[n] = c +# a decorator +def extend(cls): + return lambda f: setattr(cls, f.__name__, f) + if __name__ == '__main__': c = Compiler() schema_bin_filename = pathlib.Path(__file__).parent / '../../../schema/schema.bin' @@ -368,10 +372,11 @@ if __name__ == '__main__': x = Decoder(f.read()).next() print(c.root.schema.Schema.decode(x)) - def m(self, x): + @extend(c.root.schema.Schema) + def f(self, x): return ['yay', self.embeddedType, x] - c.root.schema.Schema.f = m print(c.root.schema.Schema.decode(x).f(123)) + print(f) print()