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
b4f0e980
Kaydet (Commit)
b4f0e980
authored
Mar 01, 2017
tarafından
Xiang Zhang
Kaydeden (comit)
GitHub
Mar 01, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-28598: Support __rmod__ for RHS subclasses of str in % string formatting operations (GH-366)
üst
02eb4b0b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
+18
-2
test_str.py
Lib/test/test_str.py
+9
-0
NEWS
Misc/NEWS
+3
-0
ceval.c
Python/ceval.c
+6
-2
No files found.
Lib/test/test_str.py
Dosyayı görüntüle @
b4f0e980
...
...
@@ -465,6 +465,15 @@ class StrTest(
self
.
assertIn
(
'str'
,
exc
)
self
.
assertIn
(
'tuple'
,
exc
)
def
test_issue28598_strsubclass_rhs
(
self
):
# A subclass of str with an __rmod__ method should be able to hook
# into the % operator
class
SubclassedStr
(
str
):
def
__rmod__
(
self
,
other
):
return
'Success, self.__rmod__({!r}) was called'
.
format
(
other
)
self
.
assertEqual
(
'lhs
%% %
r'
%
SubclassedStr
(
'rhs'
),
"Success, self.__rmod__('lhs
%% %
r') was called"
)
def
test_main
():
test_support
.
run_unittest
(
StrTest
)
...
...
Misc/NEWS
Dosyayı görüntüle @
b4f0e980
...
...
@@ -10,6 +10,9 @@ What's New in Python 2.7.14?
Core and Builtins
-----------------
- bpo-28598: Support __rmod__ for subclasses of str being called before
str.__mod__. Patch by Martijn Pieters.
- bpo-29602: Fix incorrect handling of signed zeros in complex constructor for
complex subclasses and for inputs having a __complex__ method. Patch
by Serhiy Storchaka.
...
...
Python/ceval.c
Dosyayı görüntüle @
b4f0e980
...
...
@@ -1446,10 +1446,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
{
w
=
POP
();
v
=
TOP
();
if
(
PyString_CheckExact
(
v
))
if
(
PyString_CheckExact
(
v
)
&&
(
!
PyString_Check
(
w
)
||
PyString_CheckExact
(
w
)))
{
/* fast path; string formatting, but not if the RHS is a str subclass
(see issue28598) */
x
=
PyString_Format
(
v
,
w
);
else
}
else
{
x
=
PyNumber_Remainder
(
v
,
w
);
}
Py_DECREF
(
v
);
Py_DECREF
(
w
);
SET_TOP
(
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