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
d1c7d07d
Kaydet (Commit)
d1c7d07d
authored
Eyl 25, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
make sure to give a 'as' and 'with' parser warning even after import statements #3936
üst
8e97ea9c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
13 deletions
+52
-13
test_with.py
Lib/test/test_with.py
+34
-1
NEWS
Misc/NEWS
+3
-0
parsetok.c
Parser/parsetok.c
+15
-12
No files found.
Lib/test/test_with.py
Dosyayı görüntüle @
d1c7d07d
...
...
@@ -9,6 +9,7 @@ __email__ = "mbland at acm dot org"
import
sys
import
unittest
import
StringIO
from
collections
import
deque
from
contextlib
import
GeneratorContextManager
,
contextmanager
from
test.test_support
import
run_unittest
...
...
@@ -625,12 +626,44 @@ class ExitSwallowsExceptionTestCase(unittest.TestCase):
self
.
fail
(
"ZeroDivisionError should have been raised"
)
class
NewKeywordsWarningTestCase
(
unittest
.
TestCase
):
def
check
(
self
,
code
,
word
=
None
):
save
=
sys
.
stderr
sys
.
stderr
=
stream
=
StringIO
.
StringIO
()
try
:
compile
(
code
,
"<string>"
,
"exec"
,
0
,
True
)
finally
:
sys
.
stderr
=
save
if
word
:
self
.
assert_
(
"Warning:
%
r will become a reserved keyword in Python 2.6"
%
word
in
stream
.
getvalue
())
else
:
self
.
assertEqual
(
stream
.
getvalue
(),
""
)
def
test_basic
(
self
):
self
.
check
(
"as = 4"
,
"as"
)
self
.
check
(
"with = 4"
,
"with"
)
self
.
check
(
"class as: pass"
,
"as"
)
self
.
check
(
"class with: pass"
,
"with"
)
self
.
check
(
"obj.as = 4"
,
"as"
)
self
.
check
(
"with.obj = 4"
,
"with"
)
self
.
check
(
"def with(): pass"
,
"with"
)
self
.
check
(
"do(); with = 23"
,
"with"
)
def
test_after_import
(
self
):
# issue 3936
self
.
check
(
"import sys
\n
as = 4"
,
"as"
)
self
.
check
(
"import sys
\n
with = 4"
,
"with"
)
def
test_main
():
run_unittest
(
FailureTestCase
,
NonexceptionalTestCase
,
NestedNonexceptionalTestCase
,
ExceptionalTestCase
,
NonLocalFlowControlTestCase
,
AssignmentTargetTestCase
,
ExitSwallowsExceptionTestCase
)
ExitSwallowsExceptionTestCase
,
NewKeywordsWarningTestCase
)
if
__name__
==
'__main__'
:
...
...
Misc/NEWS
Dosyayı görüntüle @
d1c7d07d
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.5.3?
Core and builtins
-----------------
- Issue #3936: The parser warnings for using "as" and "with" as variable names
didn'
t
fire
after
import
statements
.
-
Issue
#
3751
:
str
.
rpartition
would
perform
a
left
-
partition
when
called
with
a
unicode
argument
.
...
...
Parser/parsetok.c
Dosyayı görüntüle @
d1c7d07d
...
...
@@ -137,19 +137,22 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
err_ret
->
error
=
tok
->
done
;
break
;
}
if
(
type
==
ENDMARKER
&&
started
)
{
type
=
NEWLINE
;
/* Add an extra newline */
handling_with
=
handling_import
=
0
;
started
=
0
;
/* Add the right number of dedent tokens,
except if a certain flag is given --
codeop.py uses this. */
if
(
tok
->
indent
&&
!
(
flags
&
PyPARSE_DONT_IMPLY_DEDENT
))
{
tok
->
pendin
=
-
tok
->
indent
;
tok
->
indent
=
0
;
if
(
started
)
{
if
(
type
==
ENDMARKER
)
{
type
=
NEWLINE
;
/* Add an extra newline */
started
=
0
;
/* Add the right number of dedent tokens,
except if a certain flag is given --
codeop.py uses this. */
if
(
tok
->
indent
&&
!
(
flags
&
PyPARSE_DONT_IMPLY_DEDENT
))
{
tok
->
pendin
=
-
tok
->
indent
;
tok
->
indent
=
0
;
}
}
if
(
type
==
NEWLINE
)
handling_with
=
handling_import
=
0
;
}
else
started
=
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