File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -817,6 +817,7 @@ def getsourcelines(object):
817817 corresponding to the object and the line number indicates where in the
818818 original source file the first line of code was found. An OSError is
819819 raised if the source code cannot be retrieved."""
820+ object = unwrap (object )
820821 lines , lnum = findsource (object )
821822
822823 if ismodule (object ): return lines , 0
Original file line number Diff line number Diff line change @@ -109,3 +109,16 @@ def annotated(arg1: list):
109109#line 109
110110def keyword_only_arg (* , arg ):
111111 pass
112+
113+ from functools import wraps
114+
115+ def decorator (func ):
116+ @wraps (func )
117+ def fake ():
118+ return 42
119+ return fake
120+
121+ #line 121
122+ @decorator
123+ def real ():
124+ return 20
Original file line number Diff line number Diff line change @@ -377,6 +377,9 @@ def test_wrapped_decorator(self):
377377 def test_replacing_decorator (self ):
378378 self .assertSourceEqual (mod2 .gone , 9 , 10 )
379379
380+ def test_getsource_unwrap (self ):
381+ self .assertSourceEqual (mod2 .real , 122 , 124 )
382+
380383class TestOneliners (GetSourceBase ):
381384 fodderModule = mod2
382385 def test_oneline_lambda (self ):
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ Release date: TBA
1010Core and Builtins
1111-----------------
1212
13+ - Issue #1764286: Fix inspect.getsource() to support decorated functions.
14+ Patch by Claudiu Popa.
15+
1316- Issue #18554: os.__all__ includes posix functions.
1417
1518- Issue #21391: Use os.path.abspath in the shutil module.
You can’t perform that action at this time.
0 commit comments