Author maggyero
Recipients docs@python, eric.araujo, ezio.melotti, maggyero, mdk, rhettinger, willingc
Date 2019-06-08.11:51:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
With the current Python equivalent `ClassMethod` implementation of `classmethod` given in Raymond Hettinger's _Descriptor HowTo Guide_, the following code snippet:

class A:
    def f(cls, *, x): pass



> <function ClassMethod.\_\_get\_\_.<locals>.newfunc at 0x106b76268>

and raises:

> TypeError: newfunc() got an unexpected keyword argument 'x'

instead of only printing:

> <bound method A.f of <class '\_\_main\_\_.A'>>

like the `@classmethod` decorator would do.

So the `ClassMethod` implementation fails in two regards:
* it does not return a bound method to a class;
* it does not handle keyword-only arguments.

With this PR `ClassMethod` will correctly emulate `classmethod`. This approach (`types.MethodType`) is already used in the Python equivalent `Function` implementation of functions given earlier in the same guide.
Date User Action Args
2019-06-08 11:51:27maggyerosetrecipients: + maggyero, rhettinger, ezio.melotti, eric.araujo, docs@python, willingc, mdk
2019-06-08 11:51:27maggyerosetmessageid: <>
2019-06-08 11:51:27maggyerolinkissue37203 messages
2019-06-08 11:51:27maggyerocreate