Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e34809e

Browse files
authored
bpo-19072: Classmethod can wrap other classmethod like descriptors (GH-29634)
staticmethod() also became callable in Python 3.10. See: b83861f.
1 parent d32316a commit e34809e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Doc/howto/descriptor.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,9 @@ Using the non-data descriptor protocol, a pure Python version of
12641264
def __get__(self, obj, objtype=None):
12651265
return self.f
12661266

1267+
def __call__(self, *args, **kwds):
1268+
return self.f(*args, **kwds)
1269+
12671270
.. testcode::
12681271
:hide:
12691272

@@ -1272,13 +1275,17 @@ Using the non-data descriptor protocol, a pure Python version of
12721275
def f(x):
12731276
return x * 10
12741277

1278+
wrapped_ord = StaticMethod(ord)
1279+
12751280
.. doctest::
12761281
:hide:
12771282

12781283
>>> E_sim.f(3)
12791284
30
12801285
>>> E_sim().f(3)
12811286
30
1287+
>>> wrapped_ord('A')
1288+
65
12821289

12831290

12841291
Class methods
@@ -1344,7 +1351,7 @@ Using the non-data descriptor protocol, a pure Python version of
13441351
if cls is None:
13451352
cls = type(obj)
13461353
if hasattr(type(self.f), '__get__'):
1347-
return self.f.__get__(cls)
1354+
return self.f.__get__(cls, cls)
13481355
return MethodType(self.f, cls)
13491356

13501357
.. testcode::

0 commit comments

Comments
 (0)