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
399b1fe8
Kaydet (Commit)
399b1fe8
authored
Eki 25, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
give a py3k warning when 'nonlocal' is used as a variable name
üst
c756dcdd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
44 deletions
+34
-44
test_py3kwarn.py
Lib/test/test_py3kwarn.py
+23
-41
NEWS
Misc/NEWS
+3
-0
ast.c
Python/ast.c
+8
-3
No files found.
Lib/test/test_py3kwarn.py
Dosyayı görüntüle @
399b1fe8
...
...
@@ -28,53 +28,35 @@ class TestPy3KWarnings(unittest.TestCase):
exec
"`2`"
in
{}
self
.
assertWarning
(
None
,
w
,
expected
)
def
test_
bool_assign
(
self
):
def
test_
forbidden_names
(
self
):
# So we don't screw up our globals
def
safe_exec
(
expr
):
def
f
(
**
kwargs
):
pass
exec
expr
in
{
'f'
:
f
}
expected
=
"assignment to True or False is forbidden in 3.x"
tests
=
[(
"True"
,
"assignment to True or False is forbidden in 3.x"
),
(
"False"
,
"assignment to True or False is forbidden in 3.x"
),
(
"nonlocal"
,
"nonlocal is a keyword in 3.x"
)]
with
check_warnings
()
as
w
:
safe_exec
(
"True = False"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"False = True"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
try
:
safe_exec
(
"obj.False = True"
)
except
NameError
:
pass
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
try
:
safe_exec
(
"obj.True = False"
)
except
NameError
:
pass
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"def False(): pass"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"def True(): pass"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"class False: pass"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"class True: pass"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"def f(True=43): pass"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"def f(False=None): pass"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"f(False=True)"
)
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"f(True=1)"
)
self
.
assertWarning
(
None
,
w
,
expected
)
for
keyword
,
expected
in
tests
:
safe_exec
(
"{0} = False"
.
format
(
keyword
))
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
try
:
safe_exec
(
"obj.{0} = True"
.
format
(
keyword
))
except
NameError
:
pass
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"def {0}(): pass"
.
format
(
keyword
))
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"class {0}: pass"
.
format
(
keyword
))
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
safe_exec
(
"def f({0}=43): pass"
.
format
(
keyword
))
self
.
assertWarning
(
None
,
w
,
expected
)
w
.
reset
()
def
test_type_inequality_comparisons
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
399b1fe8
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
Core and Builtins
-----------------
- Using ``nonlocal`` as a variable name will now raise a Py3k SyntaxWarning
because it is a reserved work in 3.x.
- On windows, os.chdir given unicode was not working if GetCurrentDirectoryW
returned a path longer than MAX_PATH. (But It's doubtful this code path is
really executed because I cannot move to such directory on win2k)
...
...
Python/ast.c
Dosyayı görüntüle @
399b1fe8
...
...
@@ -131,9 +131,14 @@ forbidden_check(struct compiling *c, const node *n, const char *x)
{
if
(
!
strcmp
(
x
,
"None"
))
return
ast_error
(
n
,
"assignment to None"
);
if
(
Py_Py3kWarningFlag
&&
!
(
strcmp
(
x
,
"True"
)
&&
strcmp
(
x
,
"False"
))
&&
!
ast_warn
(
c
,
n
,
"assignment to True or False is forbidden in 3.x"
))
return
0
;
if
(
Py_Py3kWarningFlag
)
{
if
(
!
(
strcmp
(
x
,
"True"
)
&&
strcmp
(
x
,
"False"
))
&&
!
ast_warn
(
c
,
n
,
"assignment to True or False is forbidden in 3.x"
))
return
0
;
if
(
!
strcmp
(
x
,
"nonlocal"
)
&&
!
ast_warn
(
c
,
n
,
"nonlocal is a keyword in 3.x"
))
return
0
;
}
return
1
;
}
...
...
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