diff options
author | Georg Brandl <georg@python.org> | 2006-08-14 21:34:08 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-08-14 21:34:08 (GMT) |
commit | 2463f8f831bdf7ed562a26a13a6214f203f0b037 (patch) | |
tree | d0cb99f5c7ce3624a210f436117b8cfa7eb63445 | |
parent | 26a07b5198e47d7874eef14e15dee2cc0e644cb9 (diff) | |
download | cpython-2463f8f831bdf7ed562a26a13a6214f203f0b037.zip cpython-2463f8f831bdf7ed562a26a13a6214f203f0b037.tar.gz cpython-2463f8f831bdf7ed562a26a13a6214f203f0b037.tar.bz2 |
Make tabnanny recognize IndentationErrors raised by tokenize.
Add a test to test_inspect to make sure indented source
is recognized correctly. (fixes #1224621)
-rwxr-xr-x | Lib/tabnanny.py | 4 | ||||
-rw-r--r-- | Lib/test/inspect_fodder2.py | 9 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 3 | ||||
-rw-r--r-- | Lib/tokenize.py | 3 |
4 files changed, 18 insertions, 1 deletions
diff --git a/Lib/tabnanny.py b/Lib/tabnanny.py index f38a79f..76665ac 100755 --- a/Lib/tabnanny.py +++ b/Lib/tabnanny.py @@ -109,6 +109,10 @@ def check(file): errprint("%r: Token Error: %s" % (file, msg)) return + except IndentationError, msg: + errprint("%r: Indentation Error: %s" % (file, msg)) + return + except NannyNag, nag: badline = nag.get_lineno() line = nag.get_line() diff --git a/Lib/test/inspect_fodder2.py b/Lib/test/inspect_fodder2.py index f150ec6..3d978cf 100644 --- a/Lib/test/inspect_fodder2.py +++ b/Lib/test/inspect_fodder2.py @@ -88,3 +88,12 @@ extra85 = 'stop' def func88(): # comment return 90 + +# line 92 +def f(): + class X: + def g(): + "doc" + return 42 + return X +method_in_dynamic_class = f().g.im_func diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 300de14..fa4bd40 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -274,6 +274,9 @@ class TestBuggyCases(GetSourceBase): def test_with_comment_instead_of_docstring(self): self.assertSourceEqual(mod2.func88, 88, 90) + def test_method_in_dynamic_class(self): + self.assertSourceEqual(mod2.method_in_dynamic_class, 95, 97) + # Helper for testing classify_class_attrs. def attrs_wo_objs(cls): return [t[:3] for t in inspect.classify_class_attrs(cls)] diff --git a/Lib/tokenize.py b/Lib/tokenize.py index a30791c..a9be4cf 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -273,7 +273,8 @@ def generate_tokens(readline): while column < indents[-1]: if column not in indents: raise IndentationError( - "unindent does not match any outer indentation level") + "unindent does not match any outer indentation level", + ("<tokenize>", lnum, pos, line)) indents = indents[:-1] yield (DEDENT, '', (lnum, pos), (lnum, pos), line) |