Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idle 2.7: Calltip wrong if def contains float default value #62739

Closed
ArielBruner mannequin opened this issue Jul 24, 2013 · 4 comments
Closed

Idle 2.7: Calltip wrong if def contains float default value #62739

ArielBruner mannequin opened this issue Jul 24, 2013 · 4 comments
Assignees
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@ArielBruner
Copy link
Mannequin

ArielBruner mannequin commented Jul 24, 2013

BPO 18539
Nosy @terryjreedy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/terryjreedy'
closed_at = <Date 2013-07-26.22:22:45.043>
created_at = <Date 2013-07-24.09:02:54.937>
labels = ['expert-IDLE', 'type-bug']
title = 'Idle 2.7: Calltip wrong if def contains float default value'
updated_at = <Date 2013-07-27.19:20:32.449>
user = 'https://bugs.python.org/arielbruner'

bugs.python.org fields:

activity = <Date 2013-07-27.19:20:32.449>
actor = 'ariel_bruner'
assignee = 'terry.reedy'
closed = True
closed_date = <Date 2013-07-26.22:22:45.043>
closer = 'terry.reedy'
components = ['IDLE']
creation = <Date 2013-07-24.09:02:54.937>
creator = 'ariel_bruner'
dependencies = []
files = []
hgrepos = []
issue_num = 18539
keywords = []
message_count = 4.0
messages = ['193631', '193757', '193758', '193789']
nosy_count = 3.0
nosy_names = ['terry.reedy', 'python-dev', 'ariel_bruner']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue18539'
versions = ['Python 2.7']

@ArielBruner
Copy link
Mannequin Author

ArielBruner mannequin commented Jul 24, 2013

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):
        pass
>>> 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 -
http://stackoverflow.com/questions/17053492/pythons-idle-behavior-while-defining-fractional-default-values-to-function-para
and the problem was found to stem from the CallTips.py file (exact code lines in the link).

I believe this is the result of a fix to bpo-791968.

@ArielBruner ArielBruner mannequin added topic-IDLE type-bug An unexpected behavior, bug, or error labels Jul 24, 2013
@terryjreedy
Copy link
Member

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 bpo-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.

@terryjreedy terryjreedy changed the title Arguments tooltip wrong if def contains fractional default value Idle 2.7: Calltip wrong if def contains float default value Jul 26, 2013
@terryjreedy terryjreedy self-assigned this Jul 26, 2013
@python-dev
Copy link
Mannequin

python-dev mannequin commented Jul 26, 2013

New changeset 3236709650b0 by Terry Jan Reedy in branch '2.7':
Issue bpo-18539: Calltips now work for float default arguments.
http://hg.python.org/cpython/rev/3236709650b0

@ArielBruner
Copy link
Mannequin Author

ArielBruner mannequin commented Jul 27, 2013

Superb, and thanks for doing the actual work on fixing it.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant