def __lt__(self, other): """ This method returns ``True`` if this list is "lower than" the given `other` list. This is the case if... - this list is empty and the other is not. - the first nth item in this list which is unequal to the corresponding item in the other list, is lower than the corresponding item. If this and the other list is empty this method will return ``False``. """ if not self and other: return True elif self and not other: return False elif not self and not other: return False missing = object() for a, b in izip_longest(self, other, fillvalue=missing): if a < b: return True elif a == b: continue elif a is missing and b is not missing: return True return False
def test_izip_longest(): tests = [(((['a', 'b'], ['c', 'd']), {}), [('a', 'c'), ('b', 'd')]), (((['a'], ['c', 'd']), {}), [('a', 'c'), (None, 'd')]), (((['a'], ['c', 'd']), { 'fillvalue': 1 }), [('a', 'c'), (1, 'd')])] for test, result in tests: args, kwargs = test Assert(list(izip_longest(*args, **kwargs))) == result
def test_izip_longest(): tests = [ (((['a', 'b'], ['c', 'd']), {}), [('a', 'c'), ('b', 'd')]), (((['a'], ['c', 'd']), {}), [('a', 'c'), (None, 'd')]), (((['a'], ['c', 'd']), {'fillvalue': 1}), [('a', 'c'), (1, 'd')]) ] for test, result in tests: args, kwargs = test Assert(list(izip_longest(*args, **kwargs))) == result
def __call__(self, *args, **kwargs): collected_args = self.args.copy() for remaining, arg in izip_longest(self.remaining_params, args): if remaining is None: if self.signature.varargs is None: raise TypeError('unexpected positional argument: %r' % arg) collected_args.setdefault(self.signature.varargs, []).append(arg) elif arg is None: break else: if (remaining in collected_args and remaining in self.signature.positionals ): raise TypeError( "'%s' has been repeated: %r" % (remaining, arg) ) collected_args[remaining] = arg self.changeable_args.discard(remaining) for key, value in kwargs.iteritems(): if key in self.params: if key in collected_args: raise TypeError("'%s' has been repeated: %r" % (key, value)) self.changeable_args.discard(key) collected_args[key] = value else: if self.signature.varkwargs is None: raise TypeError('unexpected keyword argument') else: collected_args.setdefault( self.signature.varkwargs, FixedDict() )[key] = value if set(self.signature.positionals) <= set(collected_args): func_kwargs = dict(self.signature.kwparams) func_kwargs = FixedDict(self.signature.kwparams, **collected_args) func_kwargs.update(func_kwargs.pop(self.signature.varkwargs, {})) args = map(func_kwargs.pop, self.params) args += func_kwargs.pop(self.signature.varargs, []) return self.function(*args, **func_kwargs) return self._updated(collected_args)
def __call__(self, *args, **kwargs): collected_args = self.args.copy() for remaining, arg in izip_longest(self.remaining_params, args): if remaining is None: if self.signature.varargs is None: raise TypeError('unexpected positional argument: %r' % arg) collected_args.setdefault(self.signature.varargs, []).append(arg) elif arg is None: break else: if (remaining in collected_args and remaining in self.signature.positionals): raise TypeError("'%s' has been repeated: %r" % (remaining, arg)) collected_args[remaining] = arg self.changeable_args.discard(remaining) for key, value in kwargs.iteritems(): if key in self.params: if key in collected_args: raise TypeError("'%s' has been repeated: %r" % (key, value)) self.changeable_args.discard(key) collected_args[key] = value else: if self.signature.varkwargs is None: raise TypeError('unexpected keyword argument') else: collected_args.setdefault(self.signature.varkwargs, FixedDict())[key] = value if set(self.signature.positionals) <= set(collected_args): func_kwargs = dict(self.signature.kwparams) func_kwargs = FixedDict(self.signature.kwparams, **collected_args) func_kwargs.update(func_kwargs.pop(self.signature.varkwargs, {})) args = map(func_kwargs.pop, self.params) args += func_kwargs.pop(self.signature.varargs, []) return self.function(*args, **func_kwargs) return self._updated(collected_args)