def _keys_match(attribute):
 def key_match_invariant(pmap):
  if (pmap is None):
   return (True, '')
  for (key, value) in pmap.items():
   if (key != getattr(value, attribute)):
    return (False, '{} is not correct key for {}'.format(key, value))
  return (True, '')
 return key_match_invariant

def _keys_match ( attribute ) : def key_match_invariant ( pmap ) : if ( pmap is None ) : return ( True , '' ) for ( key , value ) in pmap . items ( ) : if ( key != getattr ( value , attribute ) ) : return ( False , '{} is not correct key for {}' . format ( key , value ) ) return ( True , '' ) return key_match_invariant
create an invariant for a field holding a pmap .