#NEWLINE# def _sort_states( states ) : #NEWLINE# #INDENT# pending = set ( states ) #NEWLINE# persistent = set ( ( persistent for s in pending if ( s . key is not None ) ) ) #NEWLINE# pending . difference_update ( persistent ) #NEWLINE# return ( sorted ( pending , key = operator . attrgetter ( 'insert_order' ) ) + sorted ( persistent , key = ( lambda q : q . key [ 1 ] ) ) )