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
da99d1cb
Commit
da99d1cb
authored
Jun 21, 2005
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF bug #1224621: tokenize module does not detect inconsistent dedents
parent
8fa7eb56
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Lib/test/test_tokenize.py
Lib/test/test_tokenize.py
+19
-1
Lib/tokenize.py
Lib/tokenize.py
+3
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_tokenize.py
View file @
da99d1cb
from
test.test_support
import
verbose
,
findfile
,
is_resource_enabled
from
test.test_support
import
verbose
,
findfile
,
is_resource_enabled
,
TestFailed
import
os
,
glob
,
random
from
tokenize
import
(
tokenize
,
generate_tokens
,
untokenize
,
NUMBER
,
NAME
,
OP
,
STRING
)
...
...
@@ -41,6 +41,24 @@ for f in testfiles:
test_roundtrip
(
f
)
###### Test detecton of IndentationError ######################
from
cStringIO
import
StringIO
sampleBadText
=
"""
def foo():
bar
baz
"""
try
:
for
tok
in
generate_tokens
(
StringIO
(
sampleBadText
).
readline
):
pass
except
IndentationError
:
pass
else
:
raise
TestFailed
(
"Did not detect IndentationError:"
)
###### Test example in the docs ###############################
...
...
Lib/tokenize.py
View file @
da99d1cb
...
...
@@ -271,6 +271,9 @@ def generate_tokens(readline):
indents
.
append
(
column
)
yield
(
INDENT
,
line
[:
pos
],
(
lnum
,
0
),
(
lnum
,
pos
),
line
)
while
column
<
indents
[
-
1
]:
if
column
not
in
indents
:
raise
IndentationError
(
"unindent does not match any outer indentation level"
)
indents
=
indents
[:
-
1
]
yield
(
DEDENT
,
''
,
(
lnum
,
pos
),
(
lnum
,
pos
),
line
)
...
...
Misc/NEWS
View file @
da99d1cb
...
...
@@ -147,6 +147,9 @@ Extension Modules
Library
-------
-
The
tokenize
module
now
detects
and
reports
indentation
errors
.
Bug
#
1224621.
-
The
tokenize
module
has
a
new
untokenize
()
function
to
support
a
full
roundtrip
from
lexed
tokens
back
to
Python
sourcecode
.
In
addition
,
the
generate_tokens
()
function
now
accepts
a
callable
argument
that
...
...
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