@contextlib.contextmanager
def forbid_codegen():
 from numba.targets import codegen
 patchpoints = ['CodeLibrary._finalize_final_module']
 old = {}
 def fail(*args, **kwargs):
  raise RuntimeError('codegen forbidden by test case')
 try:
  for name in patchpoints:
   parts = name.split('.')
   obj = codegen
   for attrname in parts[:(-1)]:
    obj = getattr(obj, attrname)
   attrname = parts[(-1)]
   value = getattr(obj, attrname)
   assert callable(value), ('%r should be callable' % name)
   old[(obj, attrname)] = value
   setattr(obj, attrname, fail)
  (yield)
 finally:
  for ((obj, attrname), value) in old.items():
   setattr(obj, attrname, value)

@ contextlib . contextmanager def forbid_codegen ( ) : from numba . targets import codegen patchpoints = [ 'CodeLibrary._finalize_final_module' ] old = { } def fail ( * args , ** kwargs ) : raise RuntimeError ( 'codegen forbidden by test case' ) try : for name in patchpoints : parts = name . split ( '.' ) obj = codegen for attrname in parts [ : ( - 1 ) ] : obj = getattr ( obj , attrname ) attrname = parts [ ( - 1 ) ] value = getattr ( obj , attrname ) assert callable ( value ) , ( '%r should be callable' % name ) old [ ( obj , attrname ) ] = value setattr ( obj , attrname , fail ) ( yield ) finally : for ( ( obj , attrname ) , value ) in old . items ( ) : setattr ( obj , attrname , value )
forbid llvm code generation during the execution of the context managers enclosed block .