@extend decorator

This commit is contained in:
Tony Garnock-Jones 2021-08-15 23:40:28 -04:00
parent e45ff6b020
commit 59bcced776
1 changed files with 7 additions and 2 deletions

View File

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