diff options
author | Raymond Hettinger <python@rcn.com> | 2009-01-26 02:09:03 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-01-26 02:09:03 (GMT) |
commit | 89e12963ad7f0551b325b282267ad21011aa5fd7 (patch) | |
tree | c9cd271493eea6347e0d171a6fff80db75c4accb /Lib | |
parent | d0005ff41fdb3e8806aaaf812a71ba507a83b14c (diff) | |
download | cpython-89e12963ad7f0551b325b282267ad21011aa5fd7.zip cpython-89e12963ad7f0551b325b282267ad21011aa5fd7.tar.gz cpython-89e12963ad7f0551b325b282267ad21011aa5fd7.tar.bz2 |
As discussed on python-dev, remove several operator functions
isSequenceType(), isMappingType(), and isNumberType() in favor
of using abstract base classes. Also, remove repeat() and irepeat()
in favor of mul() and imul().
After the buildbots have had a go at this. Will backport to Py3.0.1.
For Py2.7, will just mark as deprecated.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/locale.py | 4 | ||||
-rwxr-xr-x | Lib/test/test_array.py | 2 | ||||
-rw-r--r-- | Lib/test/test_bool.py | 6 | ||||
-rw-r--r-- | Lib/test/test_operator.py | 52 |
4 files changed, 2 insertions, 62 deletions
diff --git a/Lib/locale.py b/Lib/locale.py index 0bed19e..4116ef1 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -187,7 +187,7 @@ def format(percent, value, grouping=False, monetary=False, *additional): formatted = _group(formatted, monetary=monetary)[0] return formatted -import re, operator +import re, collections _percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?' r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]') @@ -207,7 +207,7 @@ def format_string(f, val, grouping=False): del new_val[i+1:i+1+starcount] i += (1 + starcount) val = tuple(new_val) - elif operator.isMappingType(val): + elif isinstance(val, collections.Mapping): for perc in percents: key = perc.group("key") val[key] = format(perc.group(), val[key], grouping) diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 2b80a7d..08c64cb 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -725,8 +725,6 @@ class BaseTest(unittest.TestCase): self.assertRaises(BufferError, operator.setitem, a, slice(0, 0), a) self.assertRaises(BufferError, operator.delitem, a, 0) self.assertRaises(BufferError, operator.delitem, a, slice(0, 1)) - self.assertRaises(BufferError, operator.irepeat, a, 2) - self.assertRaises(BufferError, operator.irepeat, a, 0) def test_weakref(self): s = array.array(self.typecode, self.example) diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 591b0eb..80229aa 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -245,16 +245,10 @@ class BoolTest(unittest.TestCase): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) - self.assertIs(operator.isNumberType(None), False) - self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) - self.assertIs(operator.isSequenceType(0), False) - self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) - self.assertIs(operator.isMappingType(1), False) - self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index 2a02dac..bf38298 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -164,31 +164,6 @@ class OperatorTestCase(unittest.TestCase): self.failUnlessRaises(TypeError, operator.invert, None) self.assertEqual(operator.inv(4), -5) - def test_isMappingType(self): - self.failUnlessRaises(TypeError, operator.isMappingType) - self.failIf(operator.isMappingType(1)) - self.failIf(operator.isMappingType(operator.isMappingType)) - self.failUnless(operator.isMappingType(operator.__dict__)) - self.failUnless(operator.isMappingType({})) - - def test_isNumberType(self): - self.failUnlessRaises(TypeError, operator.isNumberType) - self.failUnless(operator.isNumberType(8)) - self.failUnless(operator.isNumberType(8j)) - self.failUnless(operator.isNumberType(8)) - self.failUnless(operator.isNumberType(8.3)) - self.failIf(operator.isNumberType(dir())) - - def test_isSequenceType(self): - self.failUnlessRaises(TypeError, operator.isSequenceType) - self.failUnless(operator.isSequenceType(dir())) - self.failUnless(operator.isSequenceType(())) - self.failUnless(operator.isSequenceType(range(10))) - self.failUnless(operator.isSequenceType('yeahbuddy')) - self.failIf(operator.isSequenceType(3)) - class Dict(dict): pass - self.failIf(operator.isSequenceType(Dict())) - def test_lshift(self): self.failUnlessRaises(TypeError, operator.lshift) self.failUnlessRaises(TypeError, operator.lshift, None, 42) @@ -235,31 +210,6 @@ class OperatorTestCase(unittest.TestCase): self.assertRaises(TypeError, operator.pow, 1) self.assertRaises(TypeError, operator.pow, 1, 2, 3) - def test_repeat(self): - a = list(range(3)) - self.failUnlessRaises(TypeError, operator.repeat) - self.failUnlessRaises(TypeError, operator.repeat, a, None) - self.failUnless(operator.repeat(a, 2) == a+a) - self.failUnless(operator.repeat(a, 1) == a) - self.failUnless(operator.repeat(a, 0) == []) - a = (1, 2, 3) - self.failUnless(operator.repeat(a, 2) == a+a) - self.failUnless(operator.repeat(a, 1) == a) - self.failUnless(operator.repeat(a, 0) == ()) - a = '123' - self.failUnless(operator.repeat(a, 2) == a+a) - self.failUnless(operator.repeat(a, 1) == a) - self.failUnless(operator.repeat(a, 0) == '') - a = Seq1([4, 5, 6]) - self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) - self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) - self.failUnless(operator.repeat(a, 0) == []) - a = Seq2([4, 5, 6]) - self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) - self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) - self.failUnless(operator.repeat(a, 0) == []) - self.failUnlessRaises(TypeError, operator.repeat, 6, 7) - def test_rshift(self): self.failUnlessRaises(TypeError, operator.rshift) self.failUnlessRaises(TypeError, operator.rshift, None, 42) @@ -443,7 +393,6 @@ class OperatorTestCase(unittest.TestCase): self.assertEqual(operator.itruediv (c, 5), "itruediv") self.assertEqual(operator.ixor (c, 5), "ixor") self.assertEqual(operator.iconcat (c, c), "iadd") - self.assertEqual(operator.irepeat (c, 5), "imul") self.assertEqual(operator.__iadd__ (c, 5), "iadd") self.assertEqual(operator.__iand__ (c, 5), "iand") self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv") @@ -457,7 +406,6 @@ class OperatorTestCase(unittest.TestCase): self.assertEqual(operator.__itruediv__ (c, 5), "itruediv") self.assertEqual(operator.__ixor__ (c, 5), "ixor") self.assertEqual(operator.__iconcat__ (c, c), "iadd") - self.assertEqual(operator.__irepeat__ (c, 5), "imul") def test_main(verbose=None): import sys |