mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Issue #16761: Raise TypeError when int() called with base argument only.
This commit is contained in:
		
						commit
						c819b077bb
					
				
					 3 changed files with 14 additions and 13 deletions
				
			
		| 
						 | 
					@ -233,16 +233,8 @@ def test_keyword_args(self):
 | 
				
			||||||
        self.assertEqual(int(x=1.2), 1)
 | 
					        self.assertEqual(int(x=1.2), 1)
 | 
				
			||||||
        self.assertEqual(int('100', base=2), 4)
 | 
					        self.assertEqual(int('100', base=2), 4)
 | 
				
			||||||
        self.assertEqual(int(x='100', base=2), 4)
 | 
					        self.assertEqual(int(x='100', base=2), 4)
 | 
				
			||||||
 | 
					        self.assertRaises(TypeError, int, base=10)
 | 
				
			||||||
    # For example, PyPy 1.9.0 raised TypeError for these cases because it
 | 
					        self.assertRaises(TypeError, int, base=0)
 | 
				
			||||||
    # 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)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_int_base_limits(self):
 | 
					    def test_int_base_limits(self):
 | 
				
			||||||
        """Testing the supported limits of the int() base parameter."""
 | 
					        """Testing the supported limits of the int() base parameter."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
 | 
				
			||||||
Core and Builtins
 | 
					Core and Builtins
 | 
				
			||||||
-----------------
 | 
					-----------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #16761: Calling ``int()`` with *base* argument only now raises
 | 
				
			||||||
 | 
					  TypeError.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py
 | 
					- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py
 | 
				
			||||||
  when retreiving a REG_DWORD value. This corrects functions like
 | 
					  when retreiving a REG_DWORD value. This corrects functions like
 | 
				
			||||||
  winreg.QueryValueEx that may have been returning truncated values.
 | 
					  winreg.QueryValueEx that may have been returning truncated values.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4255,13 +4255,19 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 | 
				
			||||||
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist,
 | 
					    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist,
 | 
				
			||||||
                                     &x, &obase))
 | 
					                                     &x, &obase))
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    if (x == NULL)
 | 
					    if (x == NULL) {
 | 
				
			||||||
 | 
					        if (obase != NULL) {
 | 
				
			||||||
 | 
					            PyErr_SetString(PyExc_TypeError,
 | 
				
			||||||
 | 
					                            "int() missing string argument");
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        return PyLong_FromLong(0L);
 | 
					        return PyLong_FromLong(0L);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (obase == NULL)
 | 
					    if (obase == NULL)
 | 
				
			||||||
        return PyNumber_Long(x);
 | 
					        return PyNumber_Long(x);
 | 
				
			||||||
    if (!PyLong_Check(obase)) {
 | 
					    if (!PyLong_Check(obase)) {
 | 
				
			||||||
        PyErr_SetString(PyExc_TypeError,
 | 
					        PyErr_SetString(PyExc_TypeError,
 | 
				
			||||||
                        "int() arg 2 must be an integer.");
 | 
					                        "int() base must be an integer.");
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4270,7 +4276,7 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    if ((base != 0 && base < 2) || base > 36) {
 | 
					    if ((base != 0 && base < 2) || base > 36) {
 | 
				
			||||||
        PyErr_SetString(PyExc_ValueError,
 | 
					        PyErr_SetString(PyExc_ValueError,
 | 
				
			||||||
                        "int() arg 2 must be >= 2 and <= 36");
 | 
					                        "int() base must be >= 2 and <= 36");
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue