Skip to content

Commit

Permalink
Raise same error as before (#3696)
Browse files Browse the repository at this point in the history
* Raise same error as before

* Add back nice message, still raise TypeError
  • Loading branch information
ColCarroll authored Nov 29, 2019
1 parent ed55be2 commit d14ab7c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pymc3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit d14ab7c

Please sign in to comment.