Skip to content

PEP 3155 implementation #57657

Closed
Closed

Description

@pitrou
BPO 13448
Nosy @jcea, @ncoghlan, @pitrou, @vstinner, @merwok, @anacrolix
Files
  • baec10c6dcd4.diff
  • 942ba1e2f8c1.diff
  • 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 = None
    closed_at = <Date 2011-11-25.18:44:16.370>
    created_at = <Date 2011-11-21.20:53:50.231>
    labels = ['interpreter-core', 'type-feature']
    title = 'PEP 3155 implementation'
    updated_at = <Date 2012-03-18.07:47:23.423>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2012-03-18.07:47:23.423>
    actor = 'anacrolix'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-11-25.18:44:16.370>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2011-11-21.20:53:50.231>
    creator = 'pitrou'
    dependencies = []
    files = ['23744', '23766']
    hgrepos = ['91']
    issue_num = 13448
    keywords = ['patch']
    message_count = 18.0
    messages = ['148087', '148090', '148121', '148214', '148217', '148219', '148254', '148289', '148290', '148294', '148345', '148347', '148368', '148372', '148375', '149203', '149205', '156235']
    nosy_count = 8.0
    nosy_names = ['jcea', 'ncoghlan', 'pitrou', 'vstinner', 'eric.araujo', 'anacrolix', 'python-dev', 'sbt']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue13448'
    versions = ['Python 3.3']

    Activity

    1. pitrou commented on Nov 21, 2011

      @pitrou
      MemberAuthor

      Here is an issue covering PEP-3155 implementation. Hopefully a "review" link will appear in front of the hg repo URL.

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-featureA feature request or enhancement
      on Nov 21, 2011
    3. vstinner commented on Nov 21, 2011

      @vstinner
      Member

      I just have a comment: "XXX" should be replaced in "Python 3.3a0 3200 XXX".

    4. merwok commented on Nov 22, 2011

      @merwok
      Member

      Nothing to say; waiting for a doc update.

    5. pitrou commented on Nov 23, 2011

      @pitrou
      MemberAuthor

      New patch addressing Benjamin's and Victor's comments.

    6. vstinner commented on Nov 24, 2011

      @vstinner
      Member

      Ah, PyFunction_NewWithQualName is now public.

      Why an upper P in "PyFunction_NewWithQualName"? If you use an upper P, it should use an underscore in Python: __qual_name__ to be consistent. So I suggest to change the C name :-) PyFunction_NewWithQualname or PyFunction_NewWithQualifiedName. I don't have a preference between these two choices.

    7. pitrou commented on Nov 24, 2011

      @pitrou
      MemberAuthor

      Why an upper P in "PyFunction_NewWithQualName"? If you use an upper P,
      it should use an underscore in Python: __qual_name__ to be consistent.

      __getattr__ / PyObject_GetAttr.

    8. merwok commented on Nov 24, 2011

      @merwok
      Member

      Doc patch looks good.

    9. sbt commented on Nov 24, 2011

      sbtmannequin
      Mannequin

      Is it intended that pickle will use __qualname__?

    10. ncoghlan commented on Nov 24, 2011

      @ncoghlan
      Contributor

      Yes, but that can be a separate patch - step 1 is to make the attribute available, then relevant modules can subsequently be updated to use it as appropriate.

    11. pitrou commented on Nov 25, 2011

      @pitrou
      MemberAuthor

      Is it intended that pickle will use __qualname__?

      That's part of the plan for PEP-3154, yes.

    12. python-dev commented on Nov 25, 2011

      python-devmannequin
      Mannequin

      New changeset e1dbc72bd97f by Antoine Pitrou in branch 'default':
      PEP-3155 / issue bpo-13448: Qualified name for classes and functions.
      http://hg.python.org/cpython/rev/e1dbc72bd97f

    13. pitrou commented on Nov 25, 2011

      @pitrou
      MemberAuthor

      Now committed together with docs and a what's new entry. Thanks for the reviews!

    14. sbt commented on Nov 25, 2011

      sbtmannequin
      Mannequin

      There are some callables which are missing __qualname__:

      method_descriptor
      wrapper_descriptor
      builtin_function_or_method

      For the descriptors, at least, obj.__qualname__ should be equivalent to

      obj.__objclass__.__qualname__ + '.' + obj.__name__

      Were these overlooked?

        PS C:\Repos\cpython> .\PCbuild\python_d
        Python 3.3.0a0 (default, Nov 25 2011, 22:14:28) [MSC v.1500 32 bit (Intel)] on win32
        Type "help", "copyright", "credits" or "license" for more information.
        >>> import pickle
        [66213 refs]
        >>> attribs = ('__class__', '__name__', '__qualname__')
        [66220 refs]
        >>> for o in (pickle.Pickler, pickle.Pickler.dump, object.__init__, min):
        ...   print([getattr(o, a, None) for a in attribs])
        ...
        [<class 'type'>, 'Pickler', 'Pickler']
        [<class 'method_descriptor'>, 'dump', None]
        [<class 'wrapper_descriptor'>, '__init__', None]
        [<class 'builtin_function_or_method'>, 'min', None]
        [66265 refs]

      Also I notice that bound methods have a misleading __qualname__:

        >>> class A:
        ...   def f(self): pass
        ...
        [66348 refs]
        >>> A().f.__qualname__
        'A.f'

      Maybe this should be 'A().f' instead.

    15. sbt commented on Nov 26, 2011

      sbtmannequin
      Mannequin

      For builtin_function_or_method it seems obj.__qualname__ should be

      obj.__self__.__qualname__ + '.' + obj.__name__

    16. pitrou commented on Nov 26, 2011

      @pitrou
      MemberAuthor

      There are some callables which are missing __qualname__:

      method_descriptor
      wrapper_descriptor
      builtin_function_or_method

      For the descriptors, at least, obj.__qualname__ should be equivalent to

      obj.__objclass__.__qualname__ + '.' + obj.__name__

      Were these overlooked?

      Indeed, they were overlooked. Due to the way they are instantiated,
      though, it would be quite a bit harder to devise a __qualname__ for
      them.

      Also I notice that bound methods have a misleading __qualname__:

      >>> class A:
      ... def f(self): pass
      ...
      [66348 refs]
      >>> A().f.__qualname__
      'A.f'

      Maybe this should be 'A().f' instead.

      I am a bit surprised that this works at all. Apparently attribute
      lookups are redirected to the underlying function.

    17. jcea commented on Dec 11, 2011

      @jcea
      Member

      I am evaluating the use of "__qualname__" in my dtrace probes (issue bpo-13405) and I see things like this:

      """
      >>> def a() :
      ...   class b() :
      ...     pass
      ...   return b()
      ... 
      >>> c=a()
      >>> c
      <__main__.a.<locals>.b object at 0xfe37f3ac>
      >>> c.__qualname__
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      AttributeError: 'b' object has no attribute '__qualname__'
      >>> a
      <function a at 0xfe3800bc>
      >>> a.__qualname__
      'a'
      """

      I guess the class should have a __qualname__ too, haven't it?

    18. ncoghlan commented on Dec 11, 2011

      @ncoghlan
      Contributor

      No, it's only class objects that have __name__ and __qualname__, not class instances.

    19. anacrolix commented on Mar 18, 2012

      anacrolixmannequin
      Mannequin

      Doc/library/dis.rst wasn't updated for the extra pop introduced to MAKE_CLOSURE opcode.

    20. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions