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.

Title: inspect.getsource() breakage in 2.4
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: arigo, jlgijsbers, simon.percivall
Priority: high Keywords:

Created on 2005-02-18 16:26 by arigo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
inspect_bugs.diff arigo, 2005-02-18 16:26 failing test cases
Messages (5)
msg24351 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2005-02-18 16:26
In a real-life case, inspect.getsource() used to
produce the correct result on 2.3 but no longer does on

def somefunc(x, y):  # comments

With 2.4 (and 2.5 CVS) the body is completely skipped
because the first line doesn't end with a colon.  In my
opinion that's a critical problem for any code relying
on getsource(), even though such code can be considered
as relying on a large pile of fragile hacks in the
first place...

Attached is a patch for, showing the
problem (also includes a different, much more
convoluted bug example).  It seems that looking for and
around ':' in the first line isn't such a good idea;
relying more fully on the tokenizer would probably be a
better solution.

Assigned to jlgijsbers, as the author of the changes
that broke this (Dec 12th, 2004).  (No blame intended,
the change was meant to fix a different bug, and it did
msg24352 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2005-02-18 19:11
Logged In: YES 

Right now I don't have time to look into this bug deeply,
but I will do so this week. I'll note that the convoluted
example doesn't seem to be working under 2.3, though.
msg24353 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2005-03-09 11:26
Logged In: YES 

Well, I'm sorry, but I can't make the time after all. I've
asked the author of the original patch to take a look at
this patch. Note that this code isn't yet in a 2.4 release,
so we could also back this out before 2.4.1.
msg24354 - (view) Author: Simon Percivall (simon.percivall) Date: 2005-03-09 15:40
Logged In: YES 

Patch fixes this problem.
msg24355 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2005-03-12 16:39
Logged In: YES 

Simons patch has now been checked in on maint24 and HEAD.
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41599
2005-02-18 16:26:01arigocreate