gh-101860: Expose __name__ on property (GH-101876)

Useful for introspection and consistent with functions and other
descriptors.
This commit is contained in:
Eugene Toder 2024-02-20 10:14:34 -05:00 committed by GitHub
parent 9af80ec83d
commit c0b0c2f201
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 158 additions and 25 deletions

View file

@ -1162,6 +1162,17 @@ def test_importfile(self):
self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__)
class Rect:
@property
def area(self):
'''Area of the rect'''
return self.w * self.h
class Square(Rect):
area = property(lambda self: self.side**2)
class TestDescriptions(unittest.TestCase):
def test_module(self):
@ -1550,13 +1561,13 @@ def test_namedtuple_field_descriptor(self):
@requires_docstrings
def test_property(self):
class Rect:
@property
def area(self):
'''Area of the rect'''
return self.w * self.h
self.assertEqual(self._get_summary_lines(Rect.area), """\
area
Area of the rect
""")
# inherits the docstring from Rect.area
self.assertEqual(self._get_summary_lines(Square.area), """\
area
Area of the rect
""")
self.assertIn("""