Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Lib/inspect.py

Issue 1764286: inspect.getsource does not work with decorated functions
Patch Set: Created 6 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/inspect_fodder2.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Get useful information from live Python objects. 1 """Get useful information from live Python objects.
2 2
3 This module encapsulates the interface provided by the internal special 3 This module encapsulates the interface provided by the internal special
4 attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion. 4 attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion.
5 It also provides some help for examining source code and class layout. 5 It also provides some help for examining source code and class layout.
6 6
7 Here are some of the useful functions provided by this module: 7 Here are some of the useful functions provided by this module:
8 8
9 ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(), 9 ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
10 isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(), 10 isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 return lines[:blockfinder.last] 786 return lines[:blockfinder.last]
787 787
788 def getsourcelines(object): 788 def getsourcelines(object):
789 """Return a list of source lines and starting line number for an object. 789 """Return a list of source lines and starting line number for an object.
790 790
791 The argument may be a module, class, method, function, traceback, frame, 791 The argument may be a module, class, method, function, traceback, frame,
792 or code object. The source code is returned as a list of the lines 792 or code object. The source code is returned as a list of the lines
793 corresponding to the object and the line number indicates where in the 793 corresponding to the object and the line number indicates where in the
794 original source file the first line of code was found. An OSError is 794 original source file the first line of code was found. An OSError is
795 raised if the source code cannot be retrieved.""" 795 raised if the source code cannot be retrieved."""
796 object = unwrap(object)
796 lines, lnum = findsource(object) 797 lines, lnum = findsource(object)
797 798
798 if ismodule(object): return lines, 0 799 if ismodule(object): return lines, 0
799 else: return getblock(lines[lnum:]), lnum + 1 800 else: return getblock(lines[lnum:]), lnum + 1
800 801
801 def getsource(object): 802 def getsource(object):
802 """Return the text of the source code for an object. 803 """Return the text of the source code for an object.
803 804
804 The argument may be a module, class, method, function, traceback, frame, 805 The argument may be a module, class, method, function, traceback, frame,
805 or code object. The source code is returned as a single string. An 806 or code object. The source code is returned as a single string. An
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 else: 2204 else:
2204 print('Line: {}'.format(lineno)) 2205 print('Line: {}'.format(lineno))
2205 2206
2206 print('\n') 2207 print('\n')
2207 else: 2208 else:
2208 print(getsource(obj)) 2209 print(getsource(obj))
2209 2210
2210 2211
2211 if __name__ == "__main__": 2212 if __name__ == "__main__":
2212 _main() 2213 _main()
OLDNEW
« no previous file with comments | « no previous file | Lib/test/inspect_fodder2.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+