diff options
author | Johannes Gijsbers <jlg@dds.nl> | 2005-03-12 16:37:11 (GMT) |
---|---|---|
committer | Johannes Gijsbers <jlg@dds.nl> | 2005-03-12 16:37:11 (GMT) |
commit | a5855d5ace1c1426e1247272c688ccc11ae02f7c (patch) | |
tree | c841015eced138476cf55a5aaf22942cd37884b6 /Lib/inspect.py | |
parent | f77d0334f30e331f005090723cd1d2955959a8cd (diff) | |
download | cpython-a5855d5ace1c1426e1247272c688ccc11ae02f7c.zip cpython-a5855d5ace1c1426e1247272c688ccc11ae02f7c.tar.gz cpython-a5855d5ace1c1426e1247272c688ccc11ae02f7c.tar.bz2 |
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!
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index dd89932..a801a29 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -504,6 +504,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 @@ -511,11 +512,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: @@ -523,6 +521,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 |