-
Notifications
You must be signed in to change notification settings - Fork 1
Patching Classes
Angus Hollands edited this page Apr 21, 2021
·
2 revisions
Literary provides a patch
function which can monkey-patch existing classes with new methods, which is useful to break up a large class into annotate-able sections, e.g.
Here is a class. It has a
do_that()
method, and ado_the_other_thing()
method!class SomeClass: def do_this(self): pass def do_that(self): pass def do_the_other_thing(self): pass
becomes
Here is a class:
class SomeClass: def do_this(self): passIt has a
do_that()
method@patch(SomeClass) def do_that(self): passand a
do_the_other_thing()
method!@patch(SomeClass) def do_the_other_thing(self): pass
At build-time (and import time), these patch decorators disappear (through AST rewriting), and there is no import to literary
; literary
is a build-time only dependency.
Development of Literate notebooks using the IPython extension.
- Setting up the Environment
- Loading the IPython Extension
- Cell Exports
- Patching Classes
- Recommended Extensions
Building packages from a collection of Literate notebooks.