]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make tabnanny recognize IndentationErrors raised by tokenize.
authorGeorg Brandl <georg@python.org>
Mon, 14 Aug 2006 21:34:08 +0000 (21:34 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 14 Aug 2006 21:34:08 +0000 (21:34 +0000)
Add a test to test_inspect to make sure indented source
is recognized correctly. (fixes #1224621)

Lib/tabnanny.py
Lib/test/inspect_fodder2.py
Lib/test/test_inspect.py
Lib/tokenize.py

index f38a79f8a5463728969e5f6bdd13e581b4fd03f0..76665ac91a01d290f2771cb9ad6a9d15021f671c 100755 (executable)
@@ -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()
index f150ec6af5f342f9b7b6b41f9e209cde4350377a..3d978cffe3d38c088e6c4d194909a2001700cee1 100644 (file)
@@ -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
index 300de1416b9d521b8a753e1a8bee767eafc5456a..fa4bd4003f24bbccac8801683d166ab8b28a1d2e 100644 (file)
@@ -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)]
index a30791c2cdd7b24d33d206c5ebfb25946e629f73..a9be4cfe03e0b52a7dd281fecf2745f06579d541 100644 (file)
@@ -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)