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
fe879e8a
Kaydet (Commit)
fe879e8a
authored
Ara 05, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#4529: fix parser's validation for try-except-finally statements.
üst
3129ea2e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
23 deletions
+36
-23
test_parser.py
Lib/test/test_parser.py
+10
-0
NEWS
Misc/NEWS
+3
-0
parsermodule.c
Modules/parsermodule.c
+23
-23
No files found.
Lib/test/test_parser.py
Dosyayı görüntüle @
fe879e8a
...
...
@@ -200,6 +200,16 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
self
.
check_suite
(
"with open('x'): pass
\n
"
)
self
.
check_suite
(
"with open('x') as f: pass
\n
"
)
def
test_try_stmt
(
self
):
self
.
check_suite
(
"try: pass
\n
except: pass
\n
"
)
self
.
check_suite
(
"try: pass
\n
finally: pass
\n
"
)
self
.
check_suite
(
"try: pass
\n
except A: pass
\n
finally: pass
\n
"
)
self
.
check_suite
(
"try: pass
\n
except A: pass
\n
except: pass
\n
"
"finally: pass
\n
"
)
self
.
check_suite
(
"try: pass
\n
except: pass
\n
else: pass
\n
"
)
self
.
check_suite
(
"try: pass
\n
except: pass
\n
else: pass
\n
"
"finally: pass
\n
"
)
def
test_position
(
self
):
# An absolutely minimal test of position information. Better
# tests would be a big project.
...
...
Misc/NEWS
Dosyayı görüntüle @
fe879e8a
...
...
@@ -60,6 +60,9 @@ Core and Builtins
Library
-------
- Issue #4529: fix the parser module's validation of try-except-finally
statements.
- Issue #4458: getopt.gnu_getopt() now recognizes a single "-" as an argument,
not a malformed option.
...
...
Modules/parsermodule.c
Dosyayı görüntüle @
fe879e8a
...
...
@@ -2057,6 +2057,7 @@ validate_for(node *tree)
/* try_stmt:
* 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
['finally' ':' suite]
* | 'try' ':' suite 'finally' ':' suite
*
*/
...
...
@@ -2082,35 +2083,34 @@ validate_try(node *tree)
PyErr_Format
(
parser_error
,
"Illegal number of children for try/%s node."
,
name
);
}
/* Skip past except_clause sections: */
/* Handle try/finally statement */
if
(
res
&&
(
TYPE
(
CHILD
(
tree
,
pos
))
==
NAME
)
&&
(
strcmp
(
STR
(
CHILD
(
tree
,
pos
)),
"finally"
)
==
0
))
{
res
=
(
validate_numnodes
(
tree
,
6
,
"try/finally"
)
&&
validate_colon
(
CHILD
(
tree
,
4
))
&&
validate_suite
(
CHILD
(
tree
,
5
)));
return
(
res
);
}
/* try/except statement: skip past except_clause sections */
while
(
res
&&
(
TYPE
(
CHILD
(
tree
,
pos
))
==
except_clause
))
{
res
=
(
validate_except_clause
(
CHILD
(
tree
,
pos
))
&&
validate_colon
(
CHILD
(
tree
,
pos
+
1
))
&&
validate_suite
(
CHILD
(
tree
,
pos
+
2
)));
pos
+=
3
;
}
if
(
res
&&
(
pos
<
nch
))
{
res
=
validate_ntype
(
CHILD
(
tree
,
pos
),
NAME
);
if
(
res
&&
(
strcmp
(
STR
(
CHILD
(
tree
,
pos
)),
"finally"
)
==
0
))
res
=
(
validate_numnodes
(
tree
,
6
,
"try/finally"
)
&&
validate_colon
(
CHILD
(
tree
,
4
))
&&
validate_suite
(
CHILD
(
tree
,
5
)));
else
if
(
res
)
{
if
(
nch
==
(
pos
+
3
))
{
res
=
((
strcmp
(
STR
(
CHILD
(
tree
,
pos
)),
"except"
)
==
0
)
||
(
strcmp
(
STR
(
CHILD
(
tree
,
pos
)),
"else"
)
==
0
));
if
(
!
res
)
err_string
(
"illegal trailing triple in try statement"
);
}
else
if
(
nch
==
(
pos
+
6
))
{
res
=
(
validate_name
(
CHILD
(
tree
,
pos
),
"except"
)
&&
validate_colon
(
CHILD
(
tree
,
pos
+
1
))
&&
validate_suite
(
CHILD
(
tree
,
pos
+
2
))
&&
validate_name
(
CHILD
(
tree
,
pos
+
3
),
"else"
));
}
else
res
=
validate_numnodes
(
tree
,
pos
+
3
,
"try/except"
);
}
/* skip else clause */
if
(
res
&&
(
TYPE
(
CHILD
(
tree
,
pos
))
==
NAME
)
&&
(
strcmp
(
STR
(
CHILD
(
tree
,
pos
)),
"else"
)
==
0
))
{
res
=
(
validate_colon
(
CHILD
(
tree
,
pos
+
1
))
&&
validate_suite
(
CHILD
(
tree
,
pos
+
2
)));
pos
+=
3
;
}
if
(
res
&&
pos
<
nch
)
{
/* last clause must be a finally */
res
=
(
validate_name
(
CHILD
(
tree
,
pos
),
"finally"
)
&&
validate_numnodes
(
tree
,
pos
+
3
,
"try/except/finally"
)
&&
validate_colon
(
CHILD
(
tree
,
pos
+
1
))
&&
validate_suite
(
CHILD
(
tree
,
pos
+
2
)));
}
return
(
res
);
}
...
...
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