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
565e1b6b
Kaydet (Commit)
565e1b6b
authored
Haz 13, 2009
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
prevent import statements from assigning to None
üst
4afbba3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
11 deletions
+34
-11
test_compile.py
Lib/test/test_compile.py
+6
-0
NEWS
Misc/NEWS
+2
-0
ast.c
Python/ast.c
+26
-11
No files found.
Lib/test/test_compile.py
Dosyayı görüntüle @
565e1b6b
...
@@ -270,11 +270,17 @@ if 1:
...
@@ -270,11 +270,17 @@ if 1:
'(a, None) = 0, 0'
,
'(a, None) = 0, 0'
,
'for None in range(10): pass'
,
'for None in range(10): pass'
,
'def f(None): pass'
,
'def f(None): pass'
,
'import None'
,
'import x as None'
,
'from x import None'
,
'from x import y as None'
]
]
for
stmt
in
stmts
:
for
stmt
in
stmts
:
stmt
+=
"
\n
"
stmt
+=
"
\n
"
self
.
assertRaises
(
SyntaxError
,
compile
,
stmt
,
'tmp'
,
'single'
)
self
.
assertRaises
(
SyntaxError
,
compile
,
stmt
,
'tmp'
,
'single'
)
self
.
assertRaises
(
SyntaxError
,
compile
,
stmt
,
'tmp'
,
'exec'
)
self
.
assertRaises
(
SyntaxError
,
compile
,
stmt
,
'tmp'
,
'exec'
)
# This is ok.
compile
(
"from None import x"
,
"tmp"
,
"exec"
)
def
test_import
(
self
):
def
test_import
(
self
):
succeed
=
[
succeed
=
[
...
...
Misc/NEWS
Dosyayı görüntüle @
565e1b6b
...
@@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1
...
@@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1
Core and Builtins
Core and Builtins
-----------------
-----------------
- Assignment to None using import statements now raises a SyntaxError.
- In the slice AST type, the step field will always be None if a step expression
- In the slice AST type, the step field will always be None if a step expression
is not specified.
is not specified.
...
...
Python/ast.c
Dosyayı görüntüle @
565e1b6b
...
@@ -2294,7 +2294,7 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
...
@@ -2294,7 +2294,7 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
}
}
static
alias_ty
static
alias_ty
alias_for_import_name
(
struct
compiling
*
c
,
const
node
*
n
)
alias_for_import_name
(
struct
compiling
*
c
,
const
node
*
n
,
int
store
)
{
{
/*
/*
import_as_name: NAME ['as' NAME]
import_as_name: NAME ['as' NAME]
...
@@ -2305,28 +2305,38 @@ alias_for_import_name(struct compiling *c, const node *n)
...
@@ -2305,28 +2305,38 @@ alias_for_import_name(struct compiling *c, const node *n)
loop:
loop:
switch
(
TYPE
(
n
))
{
switch
(
TYPE
(
n
))
{
case
import_as_name
:
case
import_as_name
:
{
node
*
name_node
=
CHILD
(
n
,
0
);
str
=
NULL
;
str
=
NULL
;
if
(
NCH
(
n
)
==
3
)
{
if
(
NCH
(
n
)
==
3
)
{
str
=
NEW_IDENTIFIER
(
CHILD
(
n
,
2
));
node
*
str_node
=
CHILD
(
n
,
2
);
if
(
store
&&
!
forbidden_check
(
c
,
str_node
,
STR
(
str_node
)))
return
NULL
;
str
=
NEW_IDENTIFIER
(
str_node
);
if
(
!
str
)
if
(
!
str
)
return
NULL
;
return
NULL
;
}
}
name
=
NEW_IDENTIFIER
(
CHILD
(
n
,
0
));
if
(
!
forbidden_check
(
c
,
name_node
,
STR
(
name_node
)))
return
NULL
;
name
=
NEW_IDENTIFIER
(
name_node
);
if
(
!
name
)
if
(
!
name
)
return
NULL
;
return
NULL
;
return
alias
(
name
,
str
,
c
->
c_arena
);
return
alias
(
name
,
str
,
c
->
c_arena
);
}
case
dotted_as_name
:
case
dotted_as_name
:
if
(
NCH
(
n
)
==
1
)
{
if
(
NCH
(
n
)
==
1
)
{
n
=
CHILD
(
n
,
0
);
n
=
CHILD
(
n
,
0
);
goto
loop
;
goto
loop
;
}
}
else
{
else
{
alias_ty
a
=
alias_for_import_name
(
c
,
CHILD
(
n
,
0
));
node
*
asname_node
=
CHILD
(
n
,
2
);
alias_ty
a
=
alias_for_import_name
(
c
,
CHILD
(
n
,
0
),
store
);
if
(
!
a
)
if
(
!
a
)
return
NULL
;
return
NULL
;
assert
(
!
a
->
asname
);
assert
(
!
a
->
asname
);
a
->
asname
=
NEW_IDENTIFIER
(
CHILD
(
n
,
2
));
if
(
store
&&
!
forbidden_check
(
c
,
asname_node
,
STR
(
asname_node
)))
return
NULL
;
a
->
asname
=
NEW_IDENTIFIER
(
asname_node
);
if
(
!
a
->
asname
)
if
(
!
a
->
asname
)
return
NULL
;
return
NULL
;
return
a
;
return
a
;
...
@@ -2334,7 +2344,10 @@ alias_for_import_name(struct compiling *c, const node *n)
...
@@ -2334,7 +2344,10 @@ alias_for_import_name(struct compiling *c, const node *n)
break
;
break
;
case
dotted_name
:
case
dotted_name
:
if
(
NCH
(
n
)
==
1
)
{
if
(
NCH
(
n
)
==
1
)
{
name
=
NEW_IDENTIFIER
(
CHILD
(
n
,
0
));
node
*
name_node
=
CHILD
(
n
,
0
);
if
(
store
&&
!
forbidden_check
(
c
,
name_node
,
STR
(
name_node
)))
return
NULL
;
name
=
NEW_IDENTIFIER
(
name_node
);
if
(
!
name
)
if
(
!
name
)
return
NULL
;
return
NULL
;
return
alias
(
name
,
NULL
,
c
->
c_arena
);
return
alias
(
name
,
NULL
,
c
->
c_arena
);
...
@@ -2408,7 +2421,7 @@ ast_for_import_stmt(struct compiling *c, const node *n)
...
@@ -2408,7 +2421,7 @@ ast_for_import_stmt(struct compiling *c, const node *n)
if
(
!
aliases
)
if
(
!
aliases
)
return
NULL
;
return
NULL
;
for
(
i
=
0
;
i
<
NCH
(
n
);
i
+=
2
)
{
for
(
i
=
0
;
i
<
NCH
(
n
);
i
+=
2
)
{
alias_ty
import_alias
=
alias_for_import_name
(
c
,
CHILD
(
n
,
i
));
alias_ty
import_alias
=
alias_for_import_name
(
c
,
CHILD
(
n
,
i
)
,
1
);
if
(
!
import_alias
)
if
(
!
import_alias
)
return
NULL
;
return
NULL
;
asdl_seq_SET
(
aliases
,
i
/
2
,
import_alias
);
asdl_seq_SET
(
aliases
,
i
/
2
,
import_alias
);
...
@@ -2425,7 +2438,9 @@ ast_for_import_stmt(struct compiling *c, const node *n)
...
@@ -2425,7 +2438,9 @@ ast_for_import_stmt(struct compiling *c, const node *n)
optional module name */
optional module name */
for
(
idx
=
1
;
idx
<
NCH
(
n
);
idx
++
)
{
for
(
idx
=
1
;
idx
<
NCH
(
n
);
idx
++
)
{
if
(
TYPE
(
CHILD
(
n
,
idx
))
==
dotted_name
)
{
if
(
TYPE
(
CHILD
(
n
,
idx
))
==
dotted_name
)
{
mod
=
alias_for_import_name
(
c
,
CHILD
(
n
,
idx
));
mod
=
alias_for_import_name
(
c
,
CHILD
(
n
,
idx
),
0
);
if
(
!
mod
)
return
NULL
;
idx
++
;
idx
++
;
break
;
break
;
}
else
if
(
TYPE
(
CHILD
(
n
,
idx
))
!=
DOT
)
{
}
else
if
(
TYPE
(
CHILD
(
n
,
idx
))
!=
DOT
)
{
...
@@ -2466,14 +2481,14 @@ ast_for_import_stmt(struct compiling *c, const node *n)
...
@@ -2466,14 +2481,14 @@ ast_for_import_stmt(struct compiling *c, const node *n)
/* handle "from ... import *" special b/c there's no children */
/* handle "from ... import *" special b/c there's no children */
if
(
TYPE
(
n
)
==
STAR
)
{
if
(
TYPE
(
n
)
==
STAR
)
{
alias_ty
import_alias
=
alias_for_import_name
(
c
,
n
);
alias_ty
import_alias
=
alias_for_import_name
(
c
,
n
,
1
);
if
(
!
import_alias
)
if
(
!
import_alias
)
return
NULL
;
return
NULL
;
asdl_seq_SET
(
aliases
,
0
,
import_alias
);
asdl_seq_SET
(
aliases
,
0
,
import_alias
);
}
}
else
{
else
{
for
(
i
=
0
;
i
<
NCH
(
n
);
i
+=
2
)
{
for
(
i
=
0
;
i
<
NCH
(
n
);
i
+=
2
)
{
alias_ty
import_alias
=
alias_for_import_name
(
c
,
CHILD
(
n
,
i
));
alias_ty
import_alias
=
alias_for_import_name
(
c
,
CHILD
(
n
,
i
)
,
1
);
if
(
!
import_alias
)
if
(
!
import_alias
)
return
NULL
;
return
NULL
;
asdl_seq_SET
(
aliases
,
i
/
2
,
import_alias
);
asdl_seq_SET
(
aliases
,
i
/
2
,
import_alias
);
...
...
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