Anonymous avatar Anonymous committed fdf2f8f

Backport of patch #1159931/bug #1143895: inspect.getsource failed when
functions, etc., had comments after the colon, and some other cases.
This patch take a simpler approach that doesn't rely on looking for a
':'. Test cases are not backported, as test_inspect.py has been
rewritten using unittest on the trunk.

Thanks Simon Percivall!

Comments (0)

Files changed (1)

     """Provide a tokeneater() method to detect the end of a code block."""
     def __init__(self):
         self.indent = 0
+        self.islambda = False
         self.started = False
         self.passline = False
         self.last = 0
     def tokeneater(self, type, token, (srow, scol), (erow, ecol), line):
         if not self.started:
             if token in ("def", "class", "lambda"):
-                lastcolon = line.rfind(":")
-                if lastcolon:
-                    oneline = re.search(r"\w", line[lastcolon:])
-                    if oneline and line[-2:] != "\\\n":
-                        raise EndOfBlock, srow
+                if token == "lambda":
+                    self.islambda = True
                 self.started = True
             self.passline = True
         elif type == tokenize.NEWLINE:
             self.last = srow
         elif self.passline:
             pass
+        elif self.islambda:
+            raise EndOfBlock, self.last
         elif type == tokenize.INDENT:
             self.indent = self.indent + 1
             self.passline = True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.