Message345031
With the current Python equivalent `ClassMethod` implementation of `classmethod` given in Raymond Hettinger's _Descriptor HowTo Guide_, the following code snippet:
```
class A:
@ClassMethod
def f(cls, *, x): pass
print(A.f)
A.f(x=3)
```
prints:
> <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:27 | maggyero | set | recipients:
+ maggyero, rhettinger, ezio.melotti, eric.araujo, docs@python, willingc, mdk |
2019-06-08 11:51:27 | maggyero | set | messageid: <1559994687.73.0.550711459072.issue37203@roundup.psfhosted.org> |
2019-06-08 11:51:27 | maggyero | link | issue37203 messages |
2019-06-08 11:51:27 | maggyero | create | |
|