summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2005-03-12 16:38:39 (GMT)
committerJohannes Gijsbers <jlg@dds.nl>2005-03-12 16:38:39 (GMT)
commitd86254bc2514ec4fb9e62126c02ef2f6458db67d (patch)
treeec60970fbf215dd77c72b935d52bdbefb6848a9f /Lib
parente3fa0611a99d101ffa459221fa3a44f4110834b5 (diff)
downloadcpython-d86254bc2514ec4fb9e62126c02ef2f6458db67d.zip
cpython-d86254bc2514ec4fb9e62126c02ef2f6458db67d.tar.gz
cpython-d86254bc2514ec4fb9e62126c02ef2f6458db67d.tar.bz2
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!
Diffstat (limited to 'Lib')
-rw-r--r--Lib/inspect.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 05bb71b..11c96e6 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -503,6 +503,7 @@ class BlockFinder:
"""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
@@ -510,11 +511,8 @@ class BlockFinder:
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:
@@ -522,6 +520,8 @@ class BlockFinder:
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