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
99d36f15
Kaydet (Commit)
99d36f15
authored
Nis 15, 2009
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
call __float__ on str subclasses #5759
tests by R. David Murray
üst
5c991489
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
test_float.py
Lib/test/test_float.py
+12
-0
NEWS
Misc/NEWS
+2
-0
floatobject.c
Objects/floatobject.c
+3
-1
No files found.
Lib/test/test_float.py
Dosyayı görüntüle @
99d36f15
...
...
@@ -82,11 +82,23 @@ class GeneralFloatCases(unittest.TestCase):
def
__float__
(
self
):
return
42
# Issue 5759: __float__ not called on str subclasses (though it is on
# unicode subclasses).
class
FooStr
(
str
):
def
__float__
(
self
):
return
float
(
str
(
self
))
+
1
class
FooUnicode
(
unicode
):
def
__float__
(
self
):
return
float
(
unicode
(
self
))
+
1
self
.
assertAlmostEqual
(
float
(
Foo0
()),
42.
)
self
.
assertAlmostEqual
(
float
(
Foo1
()),
42.
)
self
.
assertAlmostEqual
(
float
(
Foo2
()),
42.
)
self
.
assertAlmostEqual
(
float
(
Foo3
(
21
)),
42.
)
self
.
assertRaises
(
TypeError
,
float
,
Foo4
(
42
))
self
.
assertAlmostEqual
(
float
(
FooUnicode
(
'8'
)),
9.
)
self
.
assertAlmostEqual
(
float
(
FooStr
(
'8'
)),
9.
)
def
test_floatasratio
(
self
):
for
f
,
ratio
in
[
...
...
Misc/NEWS
Dosyayı görüntüle @
99d36f15
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1
Core and Builtins
-----------------
- Issue #5759: float() didn't call __float__ on str subclasses.
- Issue #5704: the "-3" command-line option now implies "-t".
- Issue #2170: refactored xml.dom.minidom.normalize, increasing both
...
...
Objects/floatobject.c
Dosyayı görüntüle @
99d36f15
...
...
@@ -1630,7 +1630,9 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
float_subtype_new
(
type
,
args
,
kwds
);
/* Wimp out */
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|O:float"
,
kwlist
,
&
x
))
return
NULL
;
if
(
PyString_Check
(
x
))
/* If it's a string, but not a string subclass, use
PyFloat_FromString. */
if
(
PyString_CheckExact
(
x
))
return
PyFloat_FromString
(
x
,
NULL
);
return
PyNumber_Float
(
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