[Python-checkins] python/dist/src/Lib inspect.py,1.61,1.62

jlgijsbers at users.sourceforge.net jlgijsbers at users.sourceforge.net
Sat Mar 12 17:37:14 CET 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2176

Modified Files:
	inspect.py 
Log Message:
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 ':'. Thanks
Simon Percivall!


Index: inspect.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/inspect.py,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- inspect.py	11 Mar 2005 06:46:45 -0000	1.61
+++ inspect.py	12 Mar 2005 16:37:08 -0000	1.62
@@ -504,6 +504,7 @@
     """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
@@ -511,11 +512,8 @@
     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:
@@ -523,6 +521,8 @@
             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



More information about the Python-checkins mailing list