[issue15856] inspect.getsource(SomeClass) doesn't show @decorators

Thomas Kluyver report at bugs.python.org
Mon Sep 3 17:13:44 CEST 2012


New submission from Thomas Kluyver:

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 inspect.py in trunk, it looks like it will do the same thing.

----------
components: Library (Lib)
messages: 169767
nosy: takluyver
priority: normal
severity: normal
status: open
title: inspect.getsource(SomeClass) doesn't show @decorators
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15856>
_______________________________________


More information about the Python-bugs-list mailing list