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
fa21bf01
Kaydet (Commit)
fa21bf01
authored
Ock 19, 2012
tarafından
Meador Inge
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #12705: Raise SyntaxError when compiling multiple statements as single interactive statement
üst
00c7f852
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
0 deletions
+52
-0
errcode.h
Include/errcode.h
+1
-0
test_compile.py
Lib/test/test_compile.py
+28
-0
NEWS
Misc/NEWS
+3
-0
parsetok.c
Parser/parsetok.c
+17
-0
pythonrun.c
Python/pythonrun.c
+3
-0
No files found.
Include/errcode.h
Dosyayı görüntüle @
fa21bf01
...
...
@@ -30,6 +30,7 @@ extern "C" {
#define E_EOLS 24
/* EOL in single-quoted string */
#define E_LINECONT 25
/* Unexpected characters after a line continuation */
#define E_IDENTIFIER 26
/* Invalid characters in identifier */
#define E_BADSINGLE 27
/* Ill-formed single statement input */
#ifdef __cplusplus
}
...
...
Lib/test/test_compile.py
Dosyayı görüntüle @
fa21bf01
...
...
@@ -6,6 +6,12 @@ from test import support
class
TestSpecifics
(
unittest
.
TestCase
):
def
compile_single
(
self
,
source
):
compile
(
source
,
"<single>"
,
"single"
)
def
assertInvalidSingle
(
self
,
source
):
self
.
assertRaises
(
SyntaxError
,
self
.
compile_single
,
source
)
def
test_no_ending_newline
(
self
):
compile
(
"hi"
,
"<test>"
,
"exec"
)
compile
(
"hi
\r
"
,
"<test>"
,
"exec"
)
...
...
@@ -442,6 +448,28 @@ if 1:
if
isinstance
(
obj
,
types
.
CodeType
):
self
.
assertIs
(
obj
.
co_filename
,
c
.
co_filename
)
def
test_single_statement
(
self
):
self
.
compile_single
(
"1 + 2"
)
self
.
compile_single
(
"
\n
1 + 2"
)
self
.
compile_single
(
"1 + 2
\n
"
)
self
.
compile_single
(
"1 + 2
\n\n
"
)
self
.
compile_single
(
"1 + 2
\t\t\n
"
)
self
.
compile_single
(
"1 + 2
\t\t\n
"
)
self
.
compile_single
(
"1 + 2 # one plus two"
)
self
.
compile_single
(
"1; 2"
)
self
.
compile_single
(
"import sys; sys"
)
self
.
compile_single
(
"def f():
\n
pass"
)
self
.
compile_single
(
"while False:
\n
pass"
)
self
.
compile_single
(
"if x:
\n
f(x)"
)
self
.
compile_single
(
"if x:
\n
f(x)
\n
else:
\n
g(x)"
)
self
.
compile_single
(
"class T:
\n
pass"
)
def
test_bad_single_statement
(
self
):
self
.
assertInvalidSingle
(
'1
\n
2'
)
self
.
assertInvalidSingle
(
'def f(): pass'
)
self
.
assertInvalidSingle
(
'a = 13
\n
b = 187'
)
self
.
assertInvalidSingle
(
'del x
\n
del y'
)
self
.
assertInvalidSingle
(
'f()
\n
g()'
)
def
test_main
():
support
.
run_unittest
(
TestSpecifics
)
...
...
Misc/NEWS
Dosyayı görüntüle @
fa21bf01
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Issue #12705: A SyntaxError exception is now raised when attempting to
compile multiple statements as a single interactive statement.
- Fix the builtin module initialization code to store the init function for
future reinitialization.
...
...
Parser/parsetok.c
Dosyayı görüntüle @
fa21bf01
...
...
@@ -224,6 +224,23 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
if
(
err_ret
->
error
==
E_DONE
)
{
n
=
ps
->
p_tree
;
ps
->
p_tree
=
NULL
;
/* Check that the source for a single input statement really
is a single statement by looking at what is left in the
buffer after parsing. Trailing whitespace and comments
are OK. */
if
(
start
==
single_input
)
{
char
*
cur
=
tok
->
cur
;
char
c
=
*
tok
->
cur
;
while
(
c
==
' '
||
c
==
'\t'
||
c
==
'\n'
||
c
==
'\014'
)
c
=
*++
cur
;
if
(
c
&&
c
!=
'#'
)
{
err_ret
->
error
=
E_BADSINGLE
;
n
=
NULL
;
}
}
}
else
n
=
NULL
;
...
...
Python/pythonrun.c
Dosyayı görüntüle @
fa21bf01
...
...
@@ -2129,6 +2129,9 @@ err_input(perrdetail *err)
case
E_IDENTIFIER
:
msg
=
"invalid character in identifier"
;
break
;
case
E_BADSINGLE
:
msg
=
"multiple statements found while compiling a single statement"
;
break
;
default:
fprintf
(
stderr
,
"error=%d
\n
"
,
err
->
error
);
msg
=
"unknown parsing 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