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

Function name printing should use __qualname__ instead of __name__ (Python 3) #5566

Closed
admk opened this issue Apr 9, 2014 · 1 comment · Fixed by #5568
Closed

Function name printing should use __qualname__ instead of __name__ (Python 3) #5566

admk opened this issue Apr 9, 2014 · 1 comment · Fixed by #5568
Milestone

Comments

@admk
Copy link

admk commented Apr 9, 2014

There is a bug in the formatting of functions belonging to a class in IPython 2.0.0 running in Python3.

In [1]: class A:
   ...:     def f(self):
   ...:         pass
   ...:

In [2]: A.f
Out[2]: <function __main__.f>

In [3]: str(A.f)
Out[3]: '<function A.f at 0x10b283840>'

The function name formatting is using the __name__ attribute of the function instead of __qualname__, which results in incorrectly showing the function f here in our example belongs to __main__ instead of __main__.A.

A quick fix would be a one line change in https://github.com/ipython/ipython/blob/master/IPython/lib/pretty.py#L749 to use __qualname__ instead, but will break in Python 2.x as there is no __qualname__ support.

def _function_pprint(obj, p, cycle):
    """Base pprint for all functions and builtin functions."""
    if obj.__module__ in ('__builtin__', 'builtins', 'exceptions') or not obj.__module__:
        name = obj.__name__
    else:
        name = obj.__module__ + '.' + obj.__name__  # use obj.__qualname__
    p.text('<function %s>' % name)
@takluyver
Copy link
Member

Fixed in #5568.

@minrk minrk added this to the 2.1 milestone Apr 21, 2014
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants