From d14ab7cfde5c504dada8177cd4a6ce3ce7d10a86 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 29 Nov 2019 10:20:30 -0500 Subject: [PATCH] Raise same error as before (#3696) * Raise same error as before * Add back nice message, still raise TypeError --- pymc3/model.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pymc3/model.py b/pymc3/model.py index e1c76670808..120f63d433d 100644 --- a/pymc3/model.py +++ b/pymc3/model.py @@ -190,7 +190,7 @@ def __exit__(self, typ, value, traceback): # pylint: disable=unused-argument # We strip off keyword args, per the warning from # StackExchange: # DO NOT send "**kargs" to "type.__new__". It won't catch them and - # you'll get a "TypeError: type() takes 1 or 3 arguments" exception. + # you'll get a "TypeError: type() takes 1 or 3 arguments" exception. return super().__new__(cls, name, bases, dct) # FIXME: is there a more elegant way to automatically add methods to the class that @@ -200,7 +200,7 @@ def __init__(cls, name, bases, nmspc, context_class: Optional[Type]=None, **kwar if context_class is not None: cls._context_class = context_class super().__init__(name, bases, nmspc) - + def get_context(cls, error_if_none=True) -> Optional[T]: @@ -228,7 +228,7 @@ def get_contexts(cls) -> List[T]: # but since the context class is not guaranteed to exist when # the metaclass is being instantiated, I couldn't figure out a # better way. [2019/10/11:rpg] - + # no race-condition here, contexts is a thread-local object # be sure not to override contexts in a subclass however! context_class = cls.context_class @@ -284,8 +284,11 @@ def modelcontext(model: Optional['Model']) -> 'Model': """ if model is None: model = Model.get_context(error_if_none=False) + if model is None: - raise ValueError("No model on context stack.") + # TODO: This should be a ValueError, but that breaks + # ArviZ (and others?), so might need a deprecation. + raise TypeError("No model on context stack.") return model