Skip to content
Myr

Added a workaround for a pypy bug in context managers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent de7e2bc · Browse files · 2 files+31 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+31 added−0 removed

  • other:+31 added−0 removed

2 files+31 added−0 removed

modified:flask/_compat.py+24 added
69 unmodified lines
70 if this_bases is None:71 return type.__new__(cls, name, (), d)72 return meta(name, bases, d)73 return metaclass('temporary_class', None, {})747576# Certain versions of pypy have a bug where clearing the exception stack77# breaks the __exit__ function in a very peculiar way. This is currently78# true for pypy 2.2.1 for instance. The second level of exception blocks79# is necessary because pypy seems to forget to check if an exception80# happend until the next bytecode instruction?81BROKEN_PYPY_CTXMGR_EXIT = False82if hasattr(sys, 'pypy_version_info'):83 class _Mgr(object):84 def __enter__(self):85 return self86 def __exit__(self, *args):87 sys.exc_clear()88 try:89 try:90 with _Mgr():91 raise AssertionError()92 except:93 raise94 except TypeError:95 BROKEN_PYPY_CTXMGR_EXIT = True96 except AssertionError:97 pass
modified:flask/ctx.py+7 added
17 unmodified lines
1819from .globals import _request_ctx_stack, _app_ctx_stack20from .module import blueprint_is_module21from .signals import appcontext_pushed, appcontext_popped22from ._compat import BROKEN_PYPY_CTXMGR_EXIT232425class _AppCtxGlobals(object):26 """A plain object."""
160 unmodified lines
187188 def __exit__(self, exc_type, exc_value, tb):189 self.pop(exc_value)190191 if BROKEN_PYPY_CTXMGR_EXIT and exc_type is not None:192 raise exc_type, exc_value, tb193194195class RequestContext(object):196 """The request context contains all request relevant information. It is197 created at the beginning of the request and pushed to the198 `_request_ctx_stack` and removed at the end of it. It will create the
194 unmodified lines
393 # the context can be force kept alive for the test client.394 # See flask.testing for how this works.395 self.auto_pop(exc_value)396397 if BROKEN_PYPY_CTXMGR_EXIT and exc_type is not None:398 raise exc_type, exc_value, tb399400 def __repr__(self):401 return '<%s \'%s\' [%s] of %s>' % (402 self.__class__.__name__,403 self.request.url,
3 unmodified lines