[Python-checkins] python/dist/src/Lib inspect.py,1.39,1.40

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Mon, 13 Jan 2003 18:19:38 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv7580

Modified Files:
	inspect.py 
Log Message:
SF bug #661184: inspect.getsource bug

inspect.getsource would crash with one line definitions like:
   def f(x): return x
or
   f = lambda x: x


Index: inspect.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/inspect.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** inspect.py	30 Nov 2002 03:53:14 -0000	1.39
--- inspect.py	14 Jan 2003 02:19:36 -0000	1.40
***************
*** 418,422 ****
              raise IOError, 'could not find function definition'
          lnum = object.co_firstlineno - 1
!         pat = re.compile(r'^\s*def\s')
          while lnum > 0:
              if pat.match(lines[lnum]): break
--- 418,422 ----
              raise IOError, 'could not find function definition'
          lnum = object.co_firstlineno - 1
!         pat = re.compile(r'^(\s*def\s)|(.*\slambda(:|\s))')
          while lnum > 0:
              if pat.match(lines[lnum]): break
***************
*** 509,512 ****
--- 509,514 ----
      except EndOfBlock, eob:
          return lines[:eob.args[0]]
+     # Fooling the indent/dedent logic implies a one-line definition
+     return lines[:1]
  
  def getsourcelines(object):