Title: Idle 2.7: Calltip wrong if def contains float default value
Type: behavior Stage: resolved
Components: IDLE Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: ariel_bruner, python-dev, terry.reedy
Priority: normal Keywords:

Created on 2013-07-24 09:02 by ariel_bruner, last changed 2013-07-27 19:20 by ariel_bruner. This issue is now closed.

Messages (4)
msg193631 - (view) Author: ariel brunner (ariel_bruner) Date: 2013-07-24 09:02
When defining a function with factional default arguments, the <tuple> text replaces the correct values in the tooltip.

Here's an example -

>>> def f(a=0.5):
>>> f(

tooltip shows - "(a=0<tuple>)", i.e. replaces the ".5" with <tuple>.

This was found to happen on IDLE with python 2.7.3 and 2.7.5 (the latter was on 64 bit python installation on a windows 7 machine).

The problem was discussed here -
and the problem was found to stem from the file (exact code lines in the link).

I believe this is the result of a fix to issue791968.
msg193757 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-07-26 22:10
If you are the same 'ariel' as on SO, thank you for the detective work and the informative report here. Without it this 2.7-only bug would be low priority and might have sat open until we stopped patching 2.7.

The underlying issue is that a) 2.x had the 'feature' of allowing tuples of parameter names to signal automatic unpacking of tuples of arguments, and b) the unnamed tuple got a pseudoname of the form '.n' in the list of argument names, which calltips uses.

>>> def f((a,b), (c,d)): pass
>>> f.func_code.co_varnames
('.0', '.1', 'a', 'b', 'c', 'd')

Issue #791968 added the following line to change '.n' to '<tuple>'.
arg_text = "(%s)" % re.sub("\.\d+", "<tuple>", arg_text)
But this also changes float strings of form 'm.n' to 'm<tuple>'. The solution is to recognize the difference between the absence and presence of a preceding digit and not do the substitution in the latter case. Adding the negative lookbehind assertion (?<![0-9]) makes
  def f((a,b), c=0.0): 
produce (<tuple>, c=0.0). I am preparing a patch, including the test.
msg193758 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-26 22:21
New changeset 3236709650b0 by Terry Jan Reedy in branch '2.7':
Issue #18539:  Calltips now work for float default arguments.
msg193789 - (view) Author: ariel brunner (ariel_bruner) Date: 2013-07-27 19:20
Superb, and thanks for doing the actual work on fixing it.
Date User Action Args
2013-07-27 19:20:32ariel_brunersetmessages: + msg193789
2013-07-26 22:22:45terry.reedysetstatus: open -> closed
resolution: fixed
stage: test needed -> resolved
2013-07-26 22:21:55python-devsetnosy: + python-dev
messages: + msg193758
2013-07-26 22:10:30terry.reedysetnosy: + terry.reedy
title: Arguments tooltip wrong if def contains fractional default value -> Idle 2.7: Calltip wrong if def contains float default value
messages: + msg193757

assignee: terry.reedy
stage: test needed
2013-07-24 09:03:19ariel_brunersetversions: - Python 2.6
2013-07-24 09:02:55ariel_brunercreate