File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change 18
18
19
19
class Context (object ):
20
20
def __enter__ (self ):
21
- type (self ).contexts .append (self )
21
+ type (self ).get_contexts () .append (self )
22
22
return self
23
23
24
24
def __exit__ (self , typ , value , traceback ):
25
- type (self ).contexts .pop ()
25
+ type (self ).get_contexts ().pop ()
26
+
27
+ @classmethod
28
+ def get_contexts (cls ):
29
+ if not hasattr (cls , "contexts" ):
30
+ cls .contexts = []
31
+
32
+ return cls .contexts
33
+
34
+ @classmethod
35
+ def get_context (cls ):
36
+ try :
37
+ return cls .get_contexts ()[- 1 ]
38
+ except IndexError :
39
+ raise TypeError ("No context on context stack" )
26
40
27
41
def withcontext (contexttype , argname ):
28
42
def decorator (fn ):
@@ -45,14 +59,6 @@ class Model(Context):
45
59
likelihood factors of a model.
46
60
"""
47
61
48
- contexts = []
49
- @staticmethod
50
- def get_context ():
51
- try :
52
- return Model .contexts [- 1 ]
53
- except IndexError :
54
- raise TypeError ("No model context on context stack" )
55
-
56
62
def __init__ (self ):
57
63
self .vars = []
58
64
self .factors = []
You can’t perform that action at this time.
0 commit comments