Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
77736710
Commit
77736710
authored
May 04, 2006
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #1475845: Raise IndentationError for unexpected indent.
parent
61d168a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
Lib/test/test_syntax.py
Lib/test/test_syntax.py
+18
-2
Misc/NEWS
Misc/NEWS
+2
-0
Parser/parsetok.c
Parser/parsetok.c
+3
-1
No files found.
Lib/test/test_syntax.py
View file @
77736710
...
...
@@ -243,15 +243,18 @@ from test import test_support
class
SyntaxTestCase
(
unittest
.
TestCase
):
def
_check_error
(
self
,
code
,
errtext
,
filename
=
"<testcase>"
,
mode
=
"exec"
):
filename
=
"<testcase>"
,
mode
=
"exec"
,
subclass
=
None
):
"""Check that compiling code raises SyntaxError with errtext.
errtest is a regular expression that must be present in the
test of the exception raised.
test of the exception raised. If subclass is specified it
is the expected subclass of SyntaxError (e.g. IndentationError).
"""
try
:
compile
(
code
,
filename
,
mode
)
except
SyntaxError
,
err
:
if
subclass
and
not
isinstance
(
err
,
subclass
):
self
.
fail
(
"SyntaxError is not a %s"
%
subclass
.
__name__
)
mo
=
re
.
search
(
errtext
,
str
(
err
))
if
mo
is
None
:
self
.
fail
(
"SyntaxError did not contain '%r'"
%
(
errtext
,))
...
...
@@ -290,6 +293,19 @@ class SyntaxTestCase(unittest.TestCase):
:"""
)
self
.
_check_error
(
source
,
"nested scope"
)
def
test_unexpected_indent
(
self
):
self
.
_check_error
(
"foo()
\
n
bar()
\
n
"
,
"unexpected indent"
,
subclass
=
IndentationError
)
def
test_no_indent
(
self
):
self
.
_check_error
(
"if 1:
\
n
foo()"
,
"expected an indented block"
,
subclass
=
IndentationError
)
def
test_bad_outdent
(
self
):
self
.
_check_error
(
"if 1:
\
n
foo()
\
n
bar()"
,
"unindent does not match .* level"
,
subclass
=
IndentationError
)
def
test_main
():
test_support
.
run_unittest
(
SyntaxTestCase
)
from
test
import
test_syntax
...
...
Misc/NEWS
View file @
77736710
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.5 alpha 2?
Core and builtins
-----------------
- Patch #1475845: Raise IndentationError for unexpected indent.
- Patch #1479181: split open() and file() from being aliases for each other.
- Bug #1465834: '
bdist_wininst
preinstall
script
support
' was fixed
...
...
Parser/parsetok.c
View file @
77736710
...
...
@@ -194,8 +194,10 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
if
((
err_ret
->
error
=
PyParser_AddToken
(
ps
,
(
int
)
type
,
str
,
tok
->
lineno
,
col_offset
,
&
(
err_ret
->
expected
)))
!=
E_OK
)
{
if
(
err_ret
->
error
!=
E_DONE
)
if
(
err_ret
->
error
!=
E_DONE
)
{
PyObject_FREE
(
str
);
err_ret
->
token
=
type
;
}
break
;
}
}
...
...
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