Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cf095f8e
Kaydet (Commit)
cf095f8e
authored
Ara 28, 2012
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16761: Raise TypeError when int() or long() called with base argument only.
üst
3684c79e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
14 deletions
+19
-14
test_int.py
Lib/test/test_int.py
+2
-12
NEWS
Misc/NEWS
+3
-0
intobject.c
Objects/intobject.c
+7
-1
longobject.c
Objects/longobject.c
+7
-1
No files found.
Lib/test/test_int.py
Dosyayı görüntüle @
cf095f8e
...
@@ -60,6 +60,8 @@ class IntLongCommonTests(object):
...
@@ -60,6 +60,8 @@ class IntLongCommonTests(object):
self
.
assertEqual
(
self
.
ntype
(
x
=
1.2
),
1
)
self
.
assertEqual
(
self
.
ntype
(
x
=
1.2
),
1
)
self
.
assertEqual
(
self
.
ntype
(
'100'
,
base
=
2
),
4
)
self
.
assertEqual
(
self
.
ntype
(
'100'
,
base
=
2
),
4
)
self
.
assertEqual
(
self
.
ntype
(
x
=
'100'
,
base
=
2
),
4
)
self
.
assertEqual
(
self
.
ntype
(
x
=
'100'
,
base
=
2
),
4
)
self
.
assertRaises
(
TypeError
,
self
.
ntype
,
base
=
10
)
self
.
assertRaises
(
TypeError
,
self
.
ntype
,
base
=
0
)
class
IntTestCases
(
IntLongCommonTests
,
unittest
.
TestCase
):
class
IntTestCases
(
IntLongCommonTests
,
unittest
.
TestCase
):
...
@@ -365,18 +367,6 @@ class IntTestCases(IntLongCommonTests, unittest.TestCase):
...
@@ -365,18 +367,6 @@ class IntTestCases(IntLongCommonTests, unittest.TestCase):
def
test_error_on_string_base
(
self
):
def
test_error_on_string_base
(
self
):
self
.
assertRaises
(
TypeError
,
int
,
100
,
base
=
'foo'
)
self
.
assertRaises
(
TypeError
,
int
,
100
,
base
=
'foo'
)
# Include the following because in contrast CPython raises no error
# for bad integer bases when x is not given.
self
.
assertRaises
(
TypeError
,
int
,
base
=
'foo'
)
# For example, PyPy 1.9.0 raised TypeError for these cases because it
# expects x to be a string if base is given.
@test_support.cpython_only
def
test_int_base_without_x_returns_0
(
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
)
@test_support.cpython_only
@test_support.cpython_only
def
test_small_ints
(
self
):
def
test_small_ints
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
cf095f8e
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #16761: Calling ``int()`` and ``long()`` 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.
...
...
Objects/intobject.c
Dosyayı görüntüle @
cf095f8e
...
@@ -1059,8 +1059,14 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1059,8 +1059,14 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|Oi:int"
,
kwlist
,
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|Oi:int"
,
kwlist
,
&
x
,
&
base
))
&
x
,
&
base
))
return
NULL
;
return
NULL
;
if
(
x
==
NULL
)
if
(
x
==
NULL
)
{
if
(
base
!=
-
909
)
{
PyErr_SetString
(
PyExc_TypeError
,
"int() missing string argument"
);
return
NULL
;
}
return
PyInt_FromLong
(
0L
);
return
PyInt_FromLong
(
0L
);
}
if
(
base
==
-
909
)
if
(
base
==
-
909
)
return
PyNumber_Int
(
x
);
return
PyNumber_Int
(
x
);
if
(
PyString_Check
(
x
))
{
if
(
PyString_Check
(
x
))
{
...
...
Objects/longobject.c
Dosyayı görüntüle @
cf095f8e
...
@@ -3987,8 +3987,14 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3987,8 +3987,14 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|Oi:long"
,
kwlist
,
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|Oi:long"
,
kwlist
,
&
x
,
&
base
))
&
x
,
&
base
))
return
NULL
;
return
NULL
;
if
(
x
==
NULL
)
if
(
x
==
NULL
)
{
if
(
base
!=
-
909
)
{
PyErr_SetString
(
PyExc_TypeError
,
"long() missing string argument"
);
return
NULL
;
}
return
PyLong_FromLong
(
0L
);
return
PyLong_FromLong
(
0L
);
}
if
(
base
==
-
909
)
if
(
base
==
-
909
)
return
PyNumber_Long
(
x
);
return
PyNumber_Long
(
x
);
else
if
(
PyString_Check
(
x
))
{
else
if
(
PyString_Check
(
x
))
{
...
...
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