bpo-43682: @staticmethod inherits attributes (GH-25268)

Static methods (@staticmethod) and class methods (@classmethod) now
inherit the method attributes (__module__, __name__, __qualname__,
__doc__, __annotations__) and have a new __wrapped__ attribute.

Changes:

* Add a repr() method to staticmethod and classmethod types.
* Add tests on the @classmethod decorator.
This commit is contained in:
Victor Stinner 2021-04-09 17:51:22 +02:00 committed by GitHub
parent 150af75432
commit 507a574de3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 133 additions and 22 deletions

View file

@ -1142,7 +1142,8 @@ class TestDescriptions(unittest.TestCase):
'''A static method'''
...
self.assertEqual(self._get_summary_lines(X.__dict__['sm']),
"<staticmethod object>")
'sm(...)\n'
' A static method\n')
self.assertEqual(self._get_summary_lines(X.sm), """\
sm(x, y)
A static method
@ -1162,7 +1163,8 @@ sm(x, y)
'''A class method'''
...
self.assertEqual(self._get_summary_lines(X.__dict__['cm']),
"<classmethod object>")
'cm(...)\n'
' A class method\n')
self.assertEqual(self._get_summary_lines(X.cm), """\
cm(x) method of builtins.type instance
A class method