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: fix inspect.getsource breaking with line-continuation & more
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-19 01:11 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-19 01:11 patch for inspect.py
unittest_inspect.py simon.percivall, 2004-08-19 11:18 tests for patched behaviour
test_inspect_oneliners.py jlgijsbers, 2004-08-19 17:21 updated tests
Messages (7)
msg46736 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-19 01:11
The patch makes changes to inspect.py in two places:

* the pattern to match against functions at line 436 is
modified: lambdas should be matched even if not
preceded by whitespace, as long as "lambda" isn't part
of another word.

* the BlockFinder class is heavily modified. Changes are: 
  - checking for "def", "class" or "lambda" names
before setting self.started to True. Then checking the
same line for word characters after the colon (if the
colon is on that line). If so, and the line does not
end with a line continuation marker, raise EndOfBlock
immediately.
  - adding self.passline to show that the line is to be
included and no more checking is necessary on that
line. Since a NEWLINE token is not generated when a
line continuation marker exists, this allows getsource
to continue with these functions even if the following
line would not be indented.

The patch might be making a mess of the simple code,
and code such as code it now handles will probably not
be seen often. Still, it fixes the first bug shown in
"www.python.org/sf/769569".
msg46737 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-19 01:25
Logged In: YES 
user_id=329382

BTW: inspect.py CVS HEAD passes three of the tests:
test_oll, test_tlli and test_onelinefunc.
msg46738 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-19 17:21
Logged In: YES 
user_id=469548

Looks very good. I've made some small changes:

- Moved the __main__ section into a test_main() block for
running by regrtest.py
- Used the run_unittest function from test_support.py
- De-abbreviated some of the test methods
- Used comments instead of docstrings: unittest prints the
docstring of a test method instead of the name of the test
method when failing, making the failing method harder to find.

Apart from that, it looks like checkin-quality to me. Still,
it's kind of ugly to have a two separate files and two
separate methods for testing the same module, so I guess
that means I'll be converting test_inspect to unittest. I'll
try to work on that tonight and post it to
http://python.org/sf/736962 tomorrow. I'll merge these tests
into the new test_inspect after it's checked in.
msg46739 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-12-12 16:47
Logged In: YES 
user_id=469548

Well, it took a bit longer to get test_inspect ported to
unittest, but it's done now. I've also checked this in.
Thanks for the patch!
msg46740 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-12-13 11:37
Logged In: YES 
user_id=329382

Shouldn't this be considered a bug fix though? What I mean is: Shouldn't 
the patch also be checked in to the 2.4 maintain branch? Perhaps the 
ported test_inspect is a problem, but the patch itself ...
msg46741 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-12-31 09:46
Logged In: YES 
user_id=469548

Sorry for getting to this so late, but it's still before
2.4.1, right? I've checked in the patch as rev. 1.58.2.1.
msg46742 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2005-03-09 11:22
Logged In: YES 
user_id=469548

Simon, do you have the time to look at
http://python.org/sf/1143895? The patch has broken one
simple case and I really don't have the time to look into it.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40784
2004-08-19 01:11:10simon.percivallcreate