diff options
author | Johannes Gijsbers <jlg@dds.nl> | 2004-08-18 12:40:31 (GMT) |
---|---|---|
committer | Johannes Gijsbers <jlg@dds.nl> | 2004-08-18 12:40:31 (GMT) |
commit | c473c99d16b43544fffcc8a33fbc61c95061b088 (patch) | |
tree | 9f05451df2a4531c993aca7e793a2ff9f2338a32 /Lib/inspect.py | |
parent | 318a12eb0129bd75754cb3cc68076cc3b737074f (diff) | |
download | cpython-c473c99d16b43544fffcc8a33fbc61c95061b088.zip cpython-c473c99d16b43544fffcc8a33fbc61c95061b088.tar.gz cpython-c473c99d16b43544fffcc8a33fbc61c95061b088.tar.bz2 |
Patch #1006219: let inspect.getsource show '@' decorators and add tests for
this (which are rather ugly, but it'll have to do until test_inspect gets a
major overhaul and a conversion to unittest). Thanks Simon Percivall!
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 42eda77..3c47cd9 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -433,7 +433,7 @@ def findsource(object): if not hasattr(object, 'co_firstlineno'): raise IOError('could not find function definition') lnum = object.co_firstlineno - 1 - pat = re.compile(r'^(\s*def\s)|(.*\slambda(:|\s))') + pat = re.compile(r'^(\s*def\s)|(.*\slambda(:|\s))|^(\s*@)') while lnum > 0: if pat.match(lines[lnum]): break lnum = lnum - 1 @@ -509,7 +509,8 @@ class BlockFinder: def tokeneater(self, type, token, (srow, scol), (erow, ecol), line): if not self.started: - if type == tokenize.NAME: self.started = 1 + if '@' in line: pass + elif type == tokenize.NAME: self.started = 1 elif type == tokenize.NEWLINE: self.last = srow elif type == tokenize.INDENT: |