Skip to content

Commit 69745d7

Browse files
committed
separate out context from model
1 parent 31f4c59 commit 69745d7

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

pymc/model.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@
1818

1919
class Context(object):
2020
def __enter__(self):
21-
type(self).contexts.append(self)
21+
type(self).get_contexts().append(self)
2222
return self
2323

2424
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")
2640

2741
def withcontext(contexttype, argname):
2842
def decorator(fn):
@@ -45,14 +59,6 @@ class Model(Context):
4559
likelihood factors of a model.
4660
"""
4761

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-
5662
def __init__(self):
5763
self.vars = []
5864
self.factors = []

0 commit comments

Comments
 (0)