]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
check after comments, too (#13832)
authorBenjamin Peterson <benjamin@python.org>
Thu, 19 Jan 2012 22:46:13 +0000 (17:46 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 19 Jan 2012 22:46:13 +0000 (17:46 -0500)
Lib/test/test_compile.py
Parser/parsetok.c

index 7089872ee24f06e8a89ffd7beb7f6c5f951c0e7f..58b3203a9b326713dfe92c78e6764e71734bc494 100644 (file)
@@ -470,6 +470,8 @@ if 1:
         self.assertInvalidSingle('a = 13\nb = 187')
         self.assertInvalidSingle('del x\ndel y')
         self.assertInvalidSingle('f()\ng()')
+        self.assertInvalidSingle('f()\n# blah\nblah()')
+        self.assertInvalidSingle('f()\nxy # blah\nblah()')
 
 def test_main():
     support.run_unittest(TestSpecifics)
index c4b7690b2ea07cd47a0b52cd4c2ee252cb46601a..7beb735d1565e8e1bc42d0cd9dfa92821412381e 100644 (file)
@@ -234,13 +234,23 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
             char *cur = tok->cur;
             char c = *tok->cur;
 
-            while (c == ' ' || c == '\t' || c == '\n' || c == '\014')
-                c = *++cur;
-
-            if (c && c != '#') {
-                err_ret->error = E_BADSINGLE;
-                PyNode_Free(n);
-                n = NULL;
+            for (;;) {
+                while (c == ' ' || c == '\t' || c == '\n' || c == '\014')
+                    c = *++cur;
+
+                if (!c)
+                    break;
+
+                if (c != '#') {
+                    err_ret->error = E_BADSINGLE;
+                    PyNode_Free(n);
+                    n = NULL;
+                    break;
+                }
+
+                /* Suck up comment. */
+                while (c && c != '\n')
+                    c = *++cur;
             }
         }
 #endif