This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inspect.getsource show @decorators
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: jlgijsbers Nosy List: jlgijsbers, simon.percivall
Priority: normal Keywords: patch

Created on 2004-08-09 21:32 by simon.percivall, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
inspect.py.diff simon.percivall, 2004-08-11 18:22
inspect.py.3.diff simon.percivall, 2004-08-14 14:04 version 3
test_inspect_decorators.py simon.percivall, 2004-08-15 20:16
Messages (9)
msg46614 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-09 21:32
The getsource function in inspect.py breaks badly with
the @decorators.

The inspect mechanism scans backwards from the topmost
decorator until it finds some acceptable statement (it
can be anything: another function, an import line, etc.).

The patch takes care of that. It'll print all
decorators for a function as well as the function itself.
msg46615 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-10 11:19
Logged In: YES 
user_id=329382

Yeah ... It doesn't really fix anything.
msg46616 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-11 18:22
Logged In: YES 
user_id=329382

Yes, it does.
msg46617 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-12 14:16
Logged In: YES 
user_id=329382

Also fix that getsource really doesn't handle one-line
functions, with new patch.
msg46618 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-15 12:41
Logged In: YES 
user_id=469548

The patch seems okay on casual inspection, but it still
needs to have tests. Feel free to assign it to me after
adding those.
msg46619 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-15 12:56
Logged In: YES 
user_id=469548

Handling one-line functions fixes problem 1 reported in
http://python.org/sf/769569.
msg46620 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-15 15:34
Logged In: YES 
user_id=329382

Added tests for the patch.

Note that the patch for showing one-liners breaks two-line
lambdas.
msg46621 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-15 15:44
Logged In: YES 
user_id=329382

Eh, that should be:

Note that the patch for showing one-liners breaks showing
the source of two-line lambdas. Only the first line shows.
msg46622 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-18 12:58
Logged In: YES 
user_id=469548

Okay, I've checked in the patch that handles decorators as
rev 1.54 of inspect.py and rev 1.16 of test_inspect.py (note
that I integrated your tests into this file).

The oneline and twoline cases in test_inspect_decorators.py
don't fail for me, even without the patch, so I'm not
applying a patch that breaks a previously working case <wink>. 

If you're still interested in fixing this, I suggest you
write down all the test cases that should work (including
http://python.org/sf/769569 and having a twoline lambda at
the end of a file), see whether they fail now and open a new
tracker item with a patch that fixes those that don't.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40732
2004-08-09 21:32:27simon.percivallcreate