Title: inspect.getsource(SomeClass) doesn't show @decorators
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.5, Python 3.4
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, takluyver, yselivanov
Priority: normal Keywords:

Created on 2012-09-03 15:13 by takluyver, last changed 2014-07-10 18:09 by BreamoreBoy.

Messages (2)
msg169767 - (view) Author: Thomas Kluyver (takluyver) * Date: 2012-09-03 15:13
Since bug #1006219 was fixed, inspect.getsource(func) has returned the source of a function including any decorators on the function. But doing the same with a class, the returned source doesn't include decorators.

With functions, the co_firstlineno attribute of the code object points to the start of the decorators. With classes, that's not possible, so it's likely that a bit more regex trickery will be needed to scan back to decorators.

I've confirmed the same thing happens in 3.2 and 2.7, and looking at the code of in trunk, it looks like it will do the same thing.
msg222682 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-10 18:09
@Thomas sorry about the delay in getting back to you.
Date User Action Args
2014-07-10 18:09:51BreamoreBoysetnosy: + BreamoreBoy, yselivanov

messages: + msg222682
versions: + Python 3.4, Python 3.5, - Python 3.2
2012-09-03 15:13:44takluyvercreate