Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0b386d52
Commit
0b386d52
authored
Dec 28, 2012
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16761: Raise TypeError when int() called with base argument only.
parent
1e4bd53a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
Lib/test/test_int.py
Lib/test/test_int.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/longobject.c
Objects/longobject.c
+8
-2
No files found.
Lib/test/test_int.py
View file @
0b386d52
...
...
@@ -226,6 +226,14 @@ class IntTestCases(unittest.TestCase):
self
.
assertIs
(
int
(
b'10'
),
10
)
self
.
assertIs
(
int
(
b'-1'
),
-
1
)
def
test_keyword_args
(
self
):
# Test invoking int() using keyword arguments.
self
.
assertEqual
(
int
(
x
=
1.2
),
1
)
self
.
assertEqual
(
int
(
'100'
,
base
=
2
),
4
)
self
.
assertEqual
(
int
(
x
=
'100'
,
base
=
2
),
4
)
self
.
assertRaises
(
TypeError
,
int
,
base
=
10
)
self
.
assertRaises
(
TypeError
,
int
,
base
=
0
)
def
test_intconversion
(
self
):
# Test __int__()
class
ClassicMissingMethods
:
...
...
Misc/NEWS
View file @
0b386d52
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
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
when retreiving a REG_DWORD value. This corrects functions like
winreg.QueryValueEx that may have been returning truncated values.
...
...
Objects/longobject.c
View file @
0b386d52
...
...
@@ -4130,8 +4130,14 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|OO:int"
,
kwlist
,
&
x
,
&
obase
))
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
);
}
if
(
obase
==
NULL
)
return
PyNumber_Long
(
x
);
...
...
@@ -4140,7 +4146,7 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
NULL
;
if
(
overflow
||
(
base
!=
0
&&
base
<
2
)
||
base
>
36
)
{
PyErr_SetString
(
PyExc_ValueError
,
"int()
arg 2
must be >= 2 and <= 36"
);
"int()
base
must be >= 2 and <= 36"
);
return
NULL
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment