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
2cd8ce46
Kaydet (Commit)
2cd8ce46
authored
Ara 23, 2012
tarafından
Andrew Svetlov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #9856: Replace deprecation warinigs to raising TypeError in object.__format__
Patch by Florent Xicluna.
üst
bf8f2f95
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
26 deletions
+9
-26
test_builtin.py
Lib/test/test_builtin.py
+4
-10
test_unicode.py
Lib/test/test_unicode.py
+3
-5
typeobject.c
Objects/typeobject.c
+2
-11
No files found.
Lib/test/test_builtin.py
Dosyayı görüntüle @
2cd8ce46
...
...
@@ -1479,17 +1479,11 @@ class BuiltinTest(unittest.TestCase):
# --------------------------------------------------------------------
# Issue #7994: object.__format__ with a non-empty format string is
# deprecated
def
test_deprecated_format_string
(
obj
,
fmt_str
,
should_raise_warning
):
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
,
DeprecationWarning
)
format
(
obj
,
fmt_str
)
if
should_raise_warning
:
self
.
assertEqual
(
len
(
w
),
1
)
self
.
assertIsInstance
(
w
[
0
]
.
message
,
DeprecationWarning
)
self
.
assertIn
(
'object.__format__ with a non-empty format '
'string'
,
str
(
w
[
0
]
.
message
))
def
test_deprecated_format_string
(
obj
,
fmt_str
,
should_raise
):
if
should_raise
:
self
.
assertRaises
(
TypeError
,
format
,
obj
,
fmt_str
)
else
:
self
.
assertEqual
(
len
(
w
),
0
)
format
(
obj
,
fmt_str
)
fmt_strs
=
[
''
,
's'
]
...
...
Lib/test/test_unicode.py
Dosyayı görüntüle @
2cd8ce46
...
...
@@ -842,11 +842,9 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
'{0:d}'
.
format
(
G
(
'data'
)),
'G(data)'
)
self
.
assertEqual
(
'{0!s}'
.
format
(
G
(
'data'
)),
'string is data'
)
msg
=
'object.__format__ with a non-empty format string is deprecated'
with
support
.
check_warnings
((
msg
,
DeprecationWarning
)):
self
.
assertEqual
(
'{0:^10}'
.
format
(
E
(
'data'
)),
' E(data) '
)
self
.
assertEqual
(
'{0:^10s}'
.
format
(
E
(
'data'
)),
' E(data) '
)
self
.
assertEqual
(
'{0:>15s}'
.
format
(
G
(
'data'
)),
' string is data'
)
self
.
assertRaises
(
TypeError
,
'{0:^10}'
.
format
,
E
(
'data'
))
self
.
assertRaises
(
TypeError
,
'{0:^10s}'
.
format
,
E
(
'data'
))
self
.
assertRaises
(
TypeError
,
'{0:>15s}'
.
format
,
G
(
'data'
))
self
.
assertEqual
(
"{0:date:
%
Y-
%
m-
%
d}"
.
format
(
I
(
year
=
2007
,
month
=
8
,
...
...
Objects/typeobject.c
Dosyayı görüntüle @
2cd8ce46
...
...
@@ -3654,16 +3654,9 @@ object_format(PyObject *self, PyObject *args)
/* Issue 7994: If we're converting to a string, we
should reject format specifications */
if
(
PyUnicode_GET_LENGTH
(
format_spec
)
>
0
)
{
if
(
PyErr_WarnEx
(
PyExc_DeprecationWarning
,
"object.__format__ with a non-empty format "
"string is deprecated"
,
1
)
<
0
)
{
goto
done
;
}
/* Eventually this will become an error:
PyErr_Format(PyExc_TypeError,
PyErr_SetString
(
PyExc_TypeError
,
"non-empty format string passed to object.__format__"
);
goto
done
;
*/
}
result
=
PyObject_Format
(
self_as_str
,
format_spec
);
...
...
@@ -4288,12 +4281,10 @@ PyType_Ready(PyTypeObject *type)
/* Warn for a type that implements tp_compare (now known as
tp_reserved) but not tp_richcompare. */
if
(
type
->
tp_reserved
&&
!
type
->
tp_richcompare
)
{
int
error
;
error
=
PyErr_WarnFormat
(
PyExc_DeprecationWarning
,
1
,
PyErr_Format
(
PyExc_TypeError
,
"Type %.100s defines tp_reserved (formerly tp_compare) "
"but not tp_richcompare. Comparisons may not behave as intended."
,
type
->
tp_name
);
if
(
error
==
-
1
)
goto
error
;
}
...
...
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