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__.
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.
@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.
Activity
sobolevn commented on Feb 13, 2023
What about this case?
Should it be 'getter'?
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.
eltoder commented on Feb 13, 2023
@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.
pythongh-101860: Expose __name__ on property
pythongh-101860: Expose __name__ on property
pythongh-101860: Expose __name__ on property
pythongh-101860: Expose __name__ on property
pythongh-101860: Expose __name__ on property
gh-101860: Expose __name__ on property (GH-101876)
pythongh-101860: Expose __name__ on property (pythonGH-101876)
pythongh-101860: Expose __name__ on property (pythonGH-101876)
JelleZijlstra commented on May 24, 2024
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.
gh-101860: document `property.__name__` (GH-123399)
pythongh-101860: document `property.__name__` (pythonGH-123399)
[3.13] gh-101860: document `property.__name__` (GH-123399) (#123428)
picnixz commented on Aug 30, 2024
Closing since the feature is now documented in 3.13 and 3.14.
pythongh-101860: Expose __name__ on property (pythonGH-101876)
Fix util tests in Python 3.12+