]> granicus.if.org Git - python/commitdiff
Issue #16761: Raise TypeError when int() called with base argument only.
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 28 Dec 2012 08:02:42 +0000 (10:02 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 28 Dec 2012 08:02:42 +0000 (10:02 +0200)
1  2 
Lib/test/test_int.py
Misc/NEWS
Objects/longobject.c

index 52705de438a2890e8e331285f70e5be9d46ec0ad,671b20a5841111502307a638e08480ba6491a5c5..c35a42f59673d05990a19f0d491b1dbf187c69a6
@@@ -233,38 -231,9 +233,30 @@@ class IntTestCases(unittest.TestCase)
          self.assertEqual(int(x=1.2), 1)
          self.assertEqual(int('100', base=2), 4)
          self.assertEqual(int(x='100', base=2), 4)
-     # For example, PyPy 1.9.0 raised TypeError for these cases because it
-     # expects x to be a string if base is given.
-     @support.cpython_only
-     def test_base_arg_with_no_x_arg(self):
-         self.assertEqual(int(base=6), 0)
-         # Even invalid bases don't raise an exception.
-         self.assertEqual(int(base=1), 0)
-         self.assertEqual(int(base=1000), 0)
-         self.assertEqual(int(base='foo'), 0)
+         self.assertRaises(TypeError, int, base=10)
+         self.assertRaises(TypeError, int, base=0)
  
 +    def test_non_numeric_input_types(self):
 +        # Test possible non-numeric types for the argument x, including
 +        # subclasses of the explicitly documented accepted types.
 +        class CustomStr(str): pass
 +        class CustomBytes(bytes): pass
 +        class CustomByteArray(bytearray): pass
 +
 +        values = [b'100',
 +                  bytearray(b'100'),
 +                  CustomStr('100'),
 +                  CustomBytes(b'100'),
 +                  CustomByteArray(b'100')]
 +
 +        for x in values:
 +            msg = 'x has type %s' % type(x).__name__
 +            self.assertEqual(int(x), 100, msg=msg)
 +            self.assertEqual(int(x, 2), 4, msg=msg)
 +
 +    def test_string_float(self):
 +        self.assertRaises(ValueError, int, '1.2')
 +
      def test_intconversion(self):
          # Test __int__()
          class ClassicMissingMethods:
diff --cc Misc/NEWS
Simple merge
Simple merge