Skip to content

Commit 8cab699

Browse files
author
Pierre Penninckx
committed
produce try pass parsing error
1 parent 5bf309d commit 8cab699

4 files changed

+186
-2
lines changed

tests/test_dumper.py

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def test_try_finally():
193193

194194

195195
def test_try_except():
196+
check_dumps("try: pass\n\nexcept:\n pass\n")
197+
198+
199+
def test_try_except_named():
196200
check_dumps("try : pass\nexcept Exception : pass\n")
197201

198202

tests/test_grammator_control_structures.py

+141
Original file line numberDiff line numberDiff line change
@@ -1706,3 +1706,144 @@ def test_try_except_as_stmt_indent():
17061706
],
17071707
}
17081708
])
1709+
1710+
def test_try_excepts_stmt_empty_same_line():
1711+
"""
1712+
try: pass
1713+
except:
1714+
pass
1715+
"""
1716+
parse_multi([
1717+
('TRY', 'try'),
1718+
('COLON', ':'),
1719+
('PASS', 'pass', [('SPACE', ' ')]),
1720+
('ENDL', '\n'),
1721+
('EXCEPT', 'except'),
1722+
('COLON', ':'),
1723+
('ENDL', '\n', [], [('SPACE', ' ')]),
1724+
('INDENT', ''),
1725+
('PASS', 'pass'),
1726+
('ENDL', '\n'),
1727+
('DEDENT', ''),
1728+
], [
1729+
{
1730+
"type": "try",
1731+
"first_formatting": [],
1732+
"second_formatting": [],
1733+
"else": {},
1734+
"finally": {},
1735+
"excepts": [
1736+
{
1737+
"type": "except",
1738+
"first_formatting": [],
1739+
"second_formatting": [],
1740+
"third_formatting": [],
1741+
"fourth_formatting": [],
1742+
"fifth_formatting": [],
1743+
"delimiter": "",
1744+
"target": {},
1745+
"exception": {},
1746+
"value": [
1747+
{
1748+
"type": "endl",
1749+
"formatting": [],
1750+
"value": "\n",
1751+
"indent": " "
1752+
},
1753+
{
1754+
"type": "pass",
1755+
},
1756+
{
1757+
"indent": "",
1758+
"formatting": [],
1759+
"type": "endl",
1760+
"value": "\n"
1761+
}
1762+
]
1763+
}
1764+
],
1765+
"value": [
1766+
{
1767+
"type": "pass",
1768+
},
1769+
{
1770+
"indent": "",
1771+
"formatting": [],
1772+
"type": "endl",
1773+
"value": "\n"
1774+
}
1775+
],
1776+
}
1777+
])
1778+
1779+
def test_try_excepts_stmt_empty_same_line_spaced():
1780+
"""
1781+
try: pass
1782+
1783+
except:
1784+
pass
1785+
"""
1786+
parse_multi([
1787+
('TRY', 'try'),
1788+
('COLON', ':'),
1789+
('PASS', 'pass', [('SPACE', ' ')]),
1790+
('ENDL', '\n'),
1791+
('ENDL', '\n'),
1792+
('EXCEPT', 'except'),
1793+
('COLON', ':'),
1794+
('ENDL', '\n', [], [('SPACE', ' ')]),
1795+
('INDENT', ''),
1796+
('PASS', 'pass'),
1797+
('ENDL', '\n'),
1798+
('DEDENT', ''),
1799+
], [
1800+
{
1801+
"type": "try",
1802+
"first_formatting": [],
1803+
"second_formatting": [],
1804+
"else": {},
1805+
"finally": {},
1806+
"excepts": [
1807+
{
1808+
"type": "except",
1809+
"first_formatting": [],
1810+
"second_formatting": [],
1811+
"third_formatting": [],
1812+
"fourth_formatting": [],
1813+
"fifth_formatting": [],
1814+
"delimiter": "",
1815+
"target": {},
1816+
"exception": {},
1817+
"value": [
1818+
{
1819+
"type": "endl",
1820+
"formatting": [],
1821+
"value": "\n",
1822+
"indent": " "
1823+
},
1824+
{
1825+
"type": "pass",
1826+
},
1827+
{
1828+
"indent": "",
1829+
"formatting": [],
1830+
"type": "endl",
1831+
"value": "\n"
1832+
}
1833+
]
1834+
}
1835+
],
1836+
"value": [
1837+
{
1838+
"type": "pass",
1839+
},
1840+
{
1841+
"indent": "",
1842+
"formatting": [],
1843+
"type": "endl",
1844+
"value": "\n"
1845+
}
1846+
],
1847+
}
1848+
])
1849+

tests/test_indentation_marker.py

+37-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ def test_trailing_spaces():
275275
"""
276276
if a:
277277
if b:
278-
279-
278+
279+
280280
pass
281281
"""
282282
check([
@@ -337,3 +337,38 @@ def test_tab_and_spaces_because_some_people_are_horrible():
337337
('PASS', 'pass'),
338338
('DEDENT', ''),
339339
])
340+
341+
342+
def test_try_pass_on_same_line():
343+
"""
344+
try: pass
345+
346+
except:
347+
pass
348+
"""
349+
check([
350+
('TRY', 'try'),
351+
('COLON', ':', [], [('SPACE', ' ')]),
352+
('PASS', 'pass'),
353+
('ENDL', '\n'),
354+
('ENDL', '\n'),
355+
('EXCEPT', 'except'),
356+
('COLON', ':'),
357+
('ENDL', '\n', [], [('SPACE', ' ')]),
358+
('PASS', 'pass'),
359+
('ENDL', '\n'),
360+
], [
361+
('TRY', 'try'),
362+
('COLON', ':', [], [('SPACE', ' ')]),
363+
('PASS', 'pass'),
364+
('ENDL', '\n'),
365+
('ENDL', '\n'),
366+
('EXCEPT', 'except'),
367+
('COLON', ':'),
368+
('ENDL', '\n', [], [('SPACE', ' ')]),
369+
('INDENT', ''),
370+
('PASS', 'pass'),
371+
('ENDL', '\n'),
372+
('DEDENT', ''),
373+
])
374+

tests/test_spliter.py

+4
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ def test_backslash_in_comment():
367367
def test_regression():
368368
assert split("(r'[\"\\'](.|\n|\r)*[\"\\']', 'STRING'),") == ["(", "r", "'[\"\\'](.|\n|\r)*[\"\\']'", ",", " ", "'STRING'", ")", ","]
369369

370+
371+
def test_try_pass():
372+
assert split("try: pass\n\nexcept:\n pass") == ['try', ':', ' ', 'pass', '\n', '\n', 'except', ':', '\n', ' ', 'pass']
373+
370374
# TODO: make this test pass in python3 also
371375
# requires to remove dependency on ast.py
372376
if python_version == 2:

0 commit comments

Comments
 (0)