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
5e2eb35b
Kaydet (Commit)
5e2eb35b
authored
Agu 18, 2017
tarafından
Sanyam Khurana
Kaydeden (comit)
Serhiy Storchaka
Agu 18, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-30721: Show correct syntax hint in Py3 when using Py2 redirection syntax (#2345)
üst
ad7eaed5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
test_print.py
Lib/test/test_print.py
+33
-0
2017-08-18-15-15-20.bpo-30721.Hmc56z.rst
...ore and Builtins/2017-08-18-15-15-20.bpo-30721.Hmc56z.rst
+2
-0
abstract.c
Objects/abstract.c
+15
-0
No files found.
Lib/test/test_print.py
Dosyayı görüntüle @
5e2eb35b
import
unittest
import
unittest
import
sys
from
io
import
StringIO
from
io
import
StringIO
from
test
import
support
from
test
import
support
...
@@ -155,6 +156,38 @@ class TestPy2MigrationHint(unittest.TestCase):
...
@@ -155,6 +156,38 @@ class TestPy2MigrationHint(unittest.TestCase):
self
.
assertIn
(
'print("Hello World", end=" ")'
,
str
(
context
.
exception
))
self
.
assertIn
(
'print("Hello World", end=" ")'
,
str
(
context
.
exception
))
def
test_stream_redirection_hint_for_py2_migration
(
self
):
# Test correct hint produced for Py2 redirection syntax
with
self
.
assertRaises
(
TypeError
)
as
context
:
print
>>
sys
.
stderr
,
"message"
self
.
assertIn
(
'Did you mean "print(<message>, '
'file=<output_stream>)'
,
str
(
context
.
exception
))
# Test correct hint is produced in the case where RHS implements
# __rrshift__ but returns NotImplemented
with
self
.
assertRaises
(
TypeError
)
as
context
:
print
>>
42
self
.
assertIn
(
'Did you mean "print(<message>, '
'file=<output_stream>)'
,
str
(
context
.
exception
))
# Test stream redirection hint is specific to print
with
self
.
assertRaises
(
TypeError
)
as
context
:
max
>>
sys
.
stderr
self
.
assertNotIn
(
'Did you mean '
,
str
(
context
.
exception
))
# Test stream redirection hint is specific to rshift
with
self
.
assertRaises
(
TypeError
)
as
context
:
print
<<
sys
.
stderr
self
.
assertNotIn
(
'Did you mean'
,
str
(
context
.
exception
))
# Ensure right operand implementing rrshift still works
class
OverrideRRShift
:
def
__rrshift__
(
self
,
lhs
):
return
42
# Force result independent of LHS
self
.
assertEqual
(
print
>>
OverrideRRShift
(),
42
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
Misc/NEWS.d/next/Core and Builtins/2017-08-18-15-15-20.bpo-30721.Hmc56z.rst
0 → 100644
Dosyayı görüntüle @
5e2eb35b
``print`` now shows correct usage hint for using Python 2 redirection
syntax. Patch by Sanyam Khurana.
Objects/abstract.c
Dosyayı görüntüle @
5e2eb35b
...
@@ -819,6 +819,21 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name)
...
@@ -819,6 +819,21 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name)
PyObject
*
result
=
binary_op1
(
v
,
w
,
op_slot
);
PyObject
*
result
=
binary_op1
(
v
,
w
,
op_slot
);
if
(
result
==
Py_NotImplemented
)
{
if
(
result
==
Py_NotImplemented
)
{
Py_DECREF
(
result
);
Py_DECREF
(
result
);
if
(
op_slot
==
NB_SLOT
(
nb_rshift
)
&&
PyCFunction_Check
(
v
)
&&
strcmp
(((
PyCFunctionObject
*
)
v
)
->
m_ml
->
ml_name
,
"print"
)
==
0
)
{
PyErr_Format
(
PyExc_TypeError
,
"unsupported operand type(s) for %.100s: "
"'%.100s' and '%.100s'. Did you mean
\"
print(<message>, "
"file=<output_stream>)
\"
"
,
op_name
,
v
->
ob_type
->
tp_name
,
w
->
ob_type
->
tp_name
);
return
NULL
;
}
return
binop_type_error
(
v
,
w
,
op_name
);
return
binop_type_error
(
v
,
w
,
op_name
);
}
}
return
result
;
return
result
;
...
...
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