#NEWLINE# def maxcalls( ctx , f , N ) : #NEWLINE# #INDENT# '\n        Return a wrapped copy of *f* that raises ``NoConvergence`` when *f*\n        has been called more than *N* times::\n\n            >>> from mpmath import *\n            >>> mp.dps = 15\n            >>> f = maxcalls(sin, 10)\n            >>> print(sum(f(n) for n in range(10)))\n            1.95520948210738\n            >>> f(10) # doctest: +IGNORE_EXCEPTION_DETAIL\n            Traceback (most recent call last):\n              ...\n            NoConvergence: maxcalls: function evaluated 10 times\n\n        ' #NEWLINE# counter = [ 0 ] #NEWLINE# def f_maxcalls_wrapped( * args , **kwargs ) : #NEWLINE# #INDENT# counter [ 0 ] += 1 #NEWLINE# if ( counter [ 0 ] > N ) : #NEWLINE# #INDENT# raise ctx . NoConvergence ( ( 'maxcalls: function evaluated %i times' % N ) ) #NEWLINE# #UNINDENT# return f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# return f_maxcalls_wrapped