Utilities: Use number comparison for integers and floats in @sort.

This commit is contained in:
Valentin Lorentz 2014-03-20 21:17:18 +00:00
parent bfa45a6da8
commit bfb305e2b8
3 changed files with 8 additions and 4 deletions

View File

@ -110,8 +110,10 @@ class Utilities(callbacks.Plugin):
Sorts the arguments given.
"""
irc.reply(' '.join(sorted(things)))
sort = wrap(sort, [many('anything')])
irc.reply(' '.join(map(str, sorted(things))))
# Keep ints as ints, floats as floats, without comparing between numbers
# and strings.
sort = wrap(sort, [first(many(first('int', 'float')), many('anything'))])
@internationalizeDocstring
def sample(self, irc, msg, args, num, things):
@ -148,7 +150,7 @@ class Utilities(callbacks.Plugin):
tokens = callbacks.tokenize(text)
allTokens = commands + tokens
self.Proxy(irc, msg, allTokens)
apply = wrap(apply, ['something', many('anything')])
apply = wrap(apply, ['something', many('something')])
Class = Utilities

View File

@ -64,6 +64,8 @@ class UtilitiesTestCase(PluginTestCase):
def testSort(self):
self.assertResponse('sort abc cab cba bca', 'abc bca cab cba')
self.assertResponse('sort 2 12 42 7 2', '2 2 7 12 42')
self.assertResponse('sort 2 8 12.2 12.11 42 7 2', '2 2 7 8 12.11 12.2 42')
def testSample(self):
self.assertResponse('sample 1 a', 'a')

View File

@ -243,7 +243,7 @@ def _int(s):
try:
return int(s, base)
except ValueError:
if base == 10:
if base == 10 and '.' not in s:
try:
return int(float(s))
except OverflowError: