FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add `__name__` to property · Issue #101860 · python/cpython · GitHub

Repository navigation

Add __name__ to property #101860

Closed
Closed

Description

class C:
    @property
    def foo(self):
        return 1

assert C.foo.__name__ == "foo"

It would be very handy if this worked, so properties can be introspected the same way as functions, classmethods, etc. Name can be simply taken from fget the same way this is done for __isabstractmethod__.

Linked PRs

Activity

  1. sobolevn commented on Feb 13, 2023

    Member

    What about this case?

    >>> def getter(o):
    ...     return 42
    ... 
    >>> class Some:
    ...    number = property(getter)
    ... 
    >>> Some().number
    42

    Should it be 'getter'?

  2. TeamSpen210 commented on Feb 13, 2023

    Actually, property already defines __set_name__(), storing the name internally for use in formatting AttributeErrors. That's called during class creation, so it'll be accurate regardless where the callable comes from. All that's needed is for that to be exposed. This was added in #71981, but it was kept private to avoid expanding the API since a need wasn't specified.

  3. eltoder commented on Feb 13, 2023

    ContributorAuthor

    @TeamSpen210 Nice find! I think the API expansion comments were about adding name as an argument to property constructor. Adding __name__ as a read-only attribute for introspection seems very much in the spirit of python.

  4. added 4 commits that reference this issue on Feb 13, 2023
  5. added a commit that references this issue on Feb 17, 2024
  6. added a commit that references this issue on Feb 20, 2024
  7. added a commit that references this issue on Mar 4, 2024
  8. added a commit that references this issue on Apr 17, 2024
  9. JelleZijlstra commented on May 24, 2024

    Member

    This is a change to a builtin and likely has an impact on some introspection tools, so it should be mentioned in the What's New for 3.13.

  10. added a commit that references this issue on Aug 28, 2024
  11. added a commit that references this issue on Aug 28, 2024
  12. added a commit that references this issue on Aug 29, 2024
  13. picnixz commented on Aug 30, 2024

    Member

    Closing since the feature is now documented in 3.13 and 3.14.

  14. added a commit that references this issue on Jan 22, 2025
  15. added a commit that references this issue on Jun 30, 2025
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

    3.13only security fixesdocsDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL