[Patches] [ python-Patches-769142 ] CallTip trimming may loop forever.
SourceForge.net
noreply@sourceforge.net
Thu, 10 Jul 2003 10:07:23 -0700
Patches item #769142, was opened at 2003-07-10 14:13
Message generated for change (Settings changed) made by scott_daniels
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=769142&group_id=5470
Category: IDLE
Group: Python 2.3
Status: Open
Resolution: None
>Priority: 7
Submitted By: Scott David Daniels (scott_daniels)
Assigned to: Nobody/Anonymous (nobody)
Summary: CallTip trimming may loop forever.
Initial Comment:
(also applies to 2.2.x)
While trying to understand someone else's half-developed code, I found
an interesting problem in Idle. This bug is far nastier in 2.3 (which
I was using at the time).
testcase.py:
def function(arg):
'''
'''
return 1
In Idle if you type
>>> import testcase
>>> testcase.function(
The code will loop trying to place a calltip in 2.3 (in 2.2.0, it
raises an exception).
After investigation, I found the following code:
python/dist/src/Lib/idlelib/CallTips.py:
... while doc[:1] in " \t\n":
doc = doc[1:]
pos = doc.find("\n")
...
With the new string semantics for 'in', this loop will be
checking ('' in ' \t\n') (a bad state of affairs).
The following patch should fix it:
*** CallTips.py Thu Jun 26 01:16:56 2003
--- CallTips.py_old Tue Dec 31 07:59:14 2002
***************
*** 164,175 ****
# See if we can use the docstring
doc = getattr(ob, "__doc__", "")
if doc:
! doc = doc.lstrip()
pos = doc.find("\n")
if pos < 0 or pos > 70:
pos = 70
! if argText and doc:
argText += "\n"
! argText = (argText + doc[:pos]).rstrip()
return argText
--- 164,176 ----
# See if we can use the docstring
doc = getattr(ob, "__doc__", "")
if doc:
! while doc[:1] in " \t\n":
! doc = doc[1:]
pos = doc.find("\n")
if pos < 0 or pos > 70:
pos = 70
! if argText:
argText += "\n"
! argText += doc[:pos]
return argText
Unit tests are tricky (since the 2.3 problem is an infinite loop):
Attached is a test that won't get stuck in a loop.
-Scott David Daniels
Scott.Daniels@Acm.Org
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=769142&group_id=5470