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
79a922d6
Kaydet (Commit)
79a922d6
authored
May 17, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
add Py3k warnings to oct and hex. backport hex behavior (because it's not different)
üst
6c90c9fa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
15 deletions
+45
-15
test_builtin.py
Lib/test/test_builtin.py
+4
-0
test_py3kwarn.py
Lib/test/test_py3kwarn.py
+14
-0
bltinmodule.c
Python/bltinmodule.c
+27
-15
No files found.
Lib/test/test_builtin.py
Dosyayı görüntüle @
79a922d6
...
...
@@ -632,6 +632,10 @@ class BuiltinTest(unittest.TestCase):
self
.
assertEqual
(
hex
(
-
16L
),
'-0x10L'
)
self
.
assertRaises
(
TypeError
,
hex
,
{})
class
Spam
(
object
):
def
__index__
(
self
):
return
23
self
.
assertEqual
(
hex
(
Spam
()),
"0x17"
)
def
test_id
(
self
):
id
(
None
)
id
(
1
)
...
...
Lib/test/test_py3kwarn.py
Dosyayı görüntüle @
79a922d6
...
...
@@ -123,6 +123,20 @@ class TestPy3KWarnings(unittest.TestCase):
with
catch_warning
()
as
w
:
self
.
assertWarning
(
buffer
(
'a'
),
w
,
expected
)
def
test_hex_and_oct
(
self
):
class
Spam
(
object
):
def
__hex__
(
self
):
return
"0x17"
def
__oct__
(
self
):
return
"07"
expected
=
'In 3.x, oct() converts the result of __index__ to octal; '
\
'Use future_builtins.oct for this behavior. '
\
'Also, note the returned format is different.'
with
catch_warning
()
as
w
:
self
.
assertWarning
(
oct
(
Spam
()),
w
,
expected
)
expected
=
'In 3.x, hex() converts the result of __index__ to hexidecimal.'
with
catch_warning
()
as
w
:
self
.
assertWarning
(
hex
(
Spam
()),
w
,
expected
)
class
TestStdlibRemovals
(
unittest
.
TestCase
):
...
...
Python/bltinmodule.c
Dosyayı görüntüle @
79a922d6
...
...
@@ -1181,22 +1181,29 @@ builtin_hex(PyObject *self, PyObject *v)
{
PyNumberMethods
*
nb
;
PyObject
*
res
;
if
((
nb
=
v
->
ob_type
->
tp_as_number
)
==
NULL
||
nb
->
nb_hex
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"hex() argument can't be converted to hex"
);
return
NULL
;
}
res
=
(
*
nb
->
nb_hex
)(
v
);
if
(
res
&&
!
PyString_Check
(
res
))
{
PyErr_Format
(
PyExc_TypeError
,
"__hex__ returned non-string (type %.200s)"
,
res
->
ob_type
->
tp_name
);
Py_DECREF
(
res
);
return
NULL
;
nb
=
Py_TYPE
(
v
)
->
tp_as_number
;
if
(
nb
!=
NULL
&&
nb
->
nb_hex
!=
NULL
)
{
if
(
PyErr_WarnPy3k
(
"In 3.x, hex() converts "
"the result of __index__ to hexidecimal."
,
1
)
<
0
)
return
NULL
;
res
=
(
*
nb
->
nb_hex
)(
v
);
if
(
res
&&
!
PyString_Check
(
res
))
{
PyErr_Format
(
PyExc_TypeError
,
"__hex__ returned non-string (type %.200s)"
,
res
->
ob_type
->
tp_name
);
Py_DECREF
(
res
);
return
NULL
;
}
return
res
;
}
return
res
;
else
if
(
PyIndex_Check
(
v
))
return
PyNumber_ToBase
(
v
,
16
);
PyErr_SetString
(
PyExc_TypeError
,
"hex() argument can't be converted to hex"
);
return
NULL
;
}
PyDoc_STRVAR
(
hex_doc
,
...
...
@@ -1456,6 +1463,11 @@ builtin_oct(PyObject *self, PyObject *v)
"oct() argument can't be converted to oct"
);
return
NULL
;
}
if
(
PyErr_WarnPy3k
(
"In 3.x, oct() converts the result of __index__ to octal; "
"Use future_builtins.oct for this behavior. "
"Also, note the returned format is different."
,
1
)
<
0
)
return
NULL
;
res
=
(
*
nb
->
nb_oct
)(
v
);
if
(
res
&&
!
PyString_Check
(
res
))
{
PyErr_Format
(
PyExc_TypeError
,
...
...
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