mirror of
https://github.com/python/cpython.git
synced 2025-10-22 17:33:55 +00:00
gh-101860: Expose __name__ on property (GH-101876)
Useful for introspection and consistent with functions and other descriptors.
This commit is contained in:
parent
9af80ec83d
commit
c0b0c2f201
8 changed files with 158 additions and 25 deletions
|
@ -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("""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue