@@ -919,25 +919,30 @@ def __new__(cls, value):
919919 except Exception as e :
920920 exc = e
921921 result = None
922- if isinstance (result , cls ):
923- return result
924- elif (
925- Flag is not None and issubclass (cls , Flag )
926- and cls ._boundary_ is EJECT and isinstance (result , int )
927- ):
928- return result
929- else :
930- ve_exc = ValueError ("%r is not a valid %s" % (value , cls .__qualname__ ))
931- if result is None and exc is None :
932- raise ve_exc
933- elif exc is None :
934- exc = TypeError (
935- 'error in %s._missing_: returned %r instead of None or a valid member'
936- % (cls .__name__ , result )
937- )
938- if not isinstance (exc , ValueError ):
939- exc .__context__ = ve_exc
940- raise exc
922+ try :
923+ if isinstance (result , cls ):
924+ return result
925+ elif (
926+ Flag is not None and issubclass (cls , Flag )
927+ and cls ._boundary_ is EJECT and isinstance (result , int )
928+ ):
929+ return result
930+ else :
931+ ve_exc = ValueError ("%r is not a valid %s" % (value , cls .__qualname__ ))
932+ if result is None and exc is None :
933+ raise ve_exc
934+ elif exc is None :
935+ exc = TypeError (
936+ 'error in %s._missing_: returned %r instead of None or a valid member'
937+ % (cls .__name__ , result )
938+ )
939+ if not isinstance (exc , ValueError ):
940+ exc .__context__ = ve_exc
941+ raise exc
942+ finally :
943+ # ensure all variables that could hold an exception are destroyed
944+ exc = None
945+ ve_exc = None
941946
942947 def _generate_next_value_ (name , start , count , last_values ):
943948 """
0 commit comments