@@ -130,22 +130,31 @@ def cleanup(style=None):
130130 # writing a decorator with optional arguments.
131131
132132 def make_cleanup (func ):
133- @ functools . wraps (func )
134- def wrapped_function ( * args , ** kwargs ):
135- original_units_registry = matplotlib . units . registry . copy ()
136- original_settings = mpl . rcParams .copy ()
137- matplotlib . style . use ( style )
138- try :
139- if inspect . isgeneratorfunction ( func ) :
133+ if inspect . isgenerator (func ):
134+ @ functools . wraps ( func )
135+ def wrapped_callable ( * args , ** kwargs ):
136+ original_units_registry = matplotlib . units . registry .copy ()
137+ original_settings = mpl . rcParams . copy ( )
138+ matplotlib . style . use ( style )
139+ try :
140140 for yielded in func (* args , ** kwargs ):
141141 yield yielded
142- else :
142+ finally :
143+ _do_cleanup (original_units_registry ,
144+ original_settings )
145+ else :
146+ @functools .wraps (func )
147+ def wrapped_callable (* args , ** kwargs ):
148+ original_units_registry = matplotlib .units .registry .copy ()
149+ original_settings = mpl .rcParams .copy ()
150+ matplotlib .style .use (style )
151+ try :
143152 func (* args , ** kwargs )
144- finally :
145- _do_cleanup (original_units_registry ,
146- original_settings )
153+ finally :
154+ _do_cleanup (original_units_registry ,
155+ original_settings )
147156
148- return wrapped_function
157+ return wrapped_callable
149158
150159 if isinstance (style , six .string_types ):
151160 return make_cleanup
0 commit comments