def require_partition(func):
 @wraps(func)
 def new_func(*args, **kw):
  if (not is_partition(*args[:2])):
   raise nx.NetworkXError('`partition` is not a valid partition of the nodes of G')
  return func(*args, **kw)
 return new_func

def require_partition ( func ) : @ wraps ( func ) def new_func ( * args , ** kw ) : if ( not is_partition ( * args [ : 2 ] ) ) : raise nx . NetworkXError ( '`partition` is not a valid partition of the nodes of G' ) return func ( * args , ** kw ) return new_func
decorator that raises an exception if a partition is not a valid partition of the nodes of a graph .