File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -312,18 +312,15 @@ def get_context(cls, error_if_none=True) -> Optional[T]:
312312 """Return the most recently pushed context object of type ``cls``
313313 on the stack, or ``None``. If ``error_if_none`` is True (default),
314314 raise a ``TypeError`` instead of returning ``None``."""
315- idx = - 1
316- while True :
317- try :
318- candidate = cls .get_contexts ()[idx ] # type: Optional[T]
319- except IndexError as e :
320- # Calling code expects to get a TypeError if the entity
321- # is unfound, and there's too much to fix.
322- if error_if_none :
323- raise TypeError ("No %s on context stack" % str (cls ))
324- return None
325- return candidate
326- idx = idx - 1
315+ try :
316+ candidate = cls .get_contexts ()[- 1 ] # type: Optional[T]
317+ except IndexError as e :
318+ # Calling code expects to get a TypeError if the entity
319+ # is unfound, and there's too much to fix.
320+ if error_if_none :
321+ raise TypeError ("No %s on context stack" % str (cls ))
322+ return None
323+ return candidate
327324
328325 def get_contexts (cls ) -> List [T ]:
329326 """Return a stack of context instances for the ``context_class``
You can’t perform that action at this time.
0 commit comments