This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Calling a classmethod_descriptor directly raises a TypeError for wrong number of parameters.
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, python-dev
Priority: normal Keywords: patch

Created on 2012-04-30 10:11 by Mark.Shannon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
classmethoddescr_call.patch Mark.Shannon, 2012-04-30 10:11 Patch to revision 2c27093fd11f review
classmethoddescr_call.patch Mark.Shannon, 2012-05-01 09:58 review
Messages (3)
msg159687 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2012-04-30 10:11
classmethod_descriptor should either be uncallable or (better) accept the correct number of arguments.
The classmethod_descriptor can be regarded as the Python object corresponding directly to the underlying C function, as well as a descriptor object.
When called it should check that its first parameter is a subtype of the type in which it was declared, and then pass that as the 'self' parameter to the underlying C function. Currently it passes the type in which it was declared as its 'self' parameter, adding the remaining parameters.

This means that this fails:
float.__dict__['fromhex'](float, "1")
and this succeeds:
float.__dict__['fromhex']("1")
but it should be the other way around, otherwise it is impossible to pass a subtype as a parameter.

There is no tests for calling classmethod_descriptors in the test suite.

Attached patch includes tests and fixes the behaviour.
msg159748 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2012-05-01 09:58
New patch in response to review.
msg159756 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-05-01 13:56
New changeset eab5120cc208 by Benjamin Peterson in branch '3.2':
fix calling the classmethod descriptor directly (closes #14699)
http://hg.python.org/cpython/rev/eab5120cc208

New changeset e1a200dfd5db by Benjamin Peterson in branch 'default':
merge 3.2 (#14699)
http://hg.python.org/cpython/rev/e1a200dfd5db

New changeset 6484f5a51285 by Benjamin Peterson in branch '2.7':
fix calling the classmethod descriptor directly (closes #14699)
http://hg.python.org/cpython/rev/6484f5a51285
History
Date User Action Args
2022-04-11 14:57:29adminsetgithub: 58904
2012-05-01 13:56:15python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg159756

resolution: fixed
stage: resolved
2012-05-01 09:58:25Mark.Shannonsetfiles: + classmethoddescr_call.patch

messages: + msg159748
2012-04-30 10:11:21Mark.Shannoncreate