[Python-bugs-list] [ python-Bugs-548651 ] Fix the METH_CLASS implementation

noreply@sourceforge.net noreply@sourceforge.net
Mon, 09 Dec 2002 14:58:49 -0800


Bugs item #548651, was opened at 2002-04-25 11:15
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=548651&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 8
Submitted By: Thomas Heller (theller)
Assigned to: Tim Peters (tim_one)
Summary: Fix the METH_CLASS implementation

Initial Comment:
The devel-docs about METH_CLASS:

The method will be passed the type object as the first 
parameter rather than an instance of the type. This is 
used to create class methods, similar to what is 
created when using the classmethod() built-in 
function. New in version 2.3.

The code does not do it in this way. The first 
parameter the function receives is NULL, the type 
object goes together with the remaining arguments
in the second parameter (which is a tuple).

See the thread with subject 'METH_CLASS' on python-dev 
at 2002-04-25, Guido agreed that this should be fixed.


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-12-09 17:58

Message:
Logged In: YES 
user_id=31435

Thanks, fellows!  The changes were checked in,

Include/descrobject.h; new revision: 2.12
Lib/test/test_descr.py; new revision: 1.169
Objects/descrobject.c; new revision: 2.32
Objects/dictobject.c; new revision: 2.136
Objects/typeobject.c; new revision: 2.197

I still need to fix the sandbox datetime code accordingly.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-12-09 13:39

Message:
Logged In: YES 
user_id=6380

NB a small patch to test_descr is needed, as it currently
contains a test that asserts the old behavior:

*** test_descr.py	27 Nov 2002 16:29:26 -0000	1.168
--- test_descr.py	9 Dec 2002 18:38:20 -0000
***************
*** 1464,1475 ****
      a = (1, 2, 3)
      d = {'abc': 123}
      x, a1, d1 = spam.spamlist.classmeth(*a, **d)
!     veris(x, None)
!     vereq((spam.spamlist,) + a, a1)
      vereq(d, d1)
      x, a1, d1 = spam.spamlist().classmeth(*a, **d)
!     veris(x, None)
!     vereq((spam.spamlist,) + a, a1)
      vereq(d, d1)
  
  def staticmethods():
--- 1464,1475 ----
      a = (1, 2, 3)
      d = {'abc': 123}
      x, a1, d1 = spam.spamlist.classmeth(*a, **d)
!     veris(x, spam.spamlist)
!     vereq(a, a1)
      vereq(d, d1)
      x, a1, d1 = spam.spamlist().classmeth(*a, **d)
!     veris(x, spam.spamlist)
!     vereq(a, a1)
      vereq(d, d1)
  
  def staticmethods():


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-12-09 13:31

Message:
Logged In: YES 
user_id=6380

>From a brief skim of the patch, it looks like this is indeed
what's needed. I guess Tim can check it in (with my helpp,
I'm sitting right behind him).

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-12-09 00:12

Message:
Logged In: YES 
user_id=31435

Guido, does this patch match your and Fred's intent?  I 
want to get this fixed, as it pops up a dozen times in the 
datetime project.  Feel free to do a braindump on me 
tomorrow and make it my headache.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2002-12-06 13:51

Message:
Logged In: YES 
user_id=11105

Ok, here's a first outline in form of a patch. Probably the
same should be done for staticmethods.
All the tests pass on Windows except bz2 and bsddb which I
didn't build, and test_descr failes because
Modules/xxsubtype.c needs to be updated.

If this looks ok, I'm willing to continue - it didn't take
much longer than an hour so far.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-12-06 12:19

Message:
Logged In: YES 
user_id=31435

This also affects the C implementation of the datetime 
module.  While it would be very nice to get it fixed before 
alpha 1, it doesn't need to be fixed before beta 1.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-12-06 10:12

Message:
Logged In: YES 
user_id=3066

I'd love to see this fixed.  Priorities at work may not
allow me to spend any time on this; patches would be welcome.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2002-12-06 03:19

Message:
Logged In: YES 
user_id=11105

Will this be fixed before 2.3a? Now is the *last* chance to do 
this, since it changes the sematics of C code.
In http://mail.python.org/pipermail/python-dev/2002-
April/023574.html, Guido wrote the following:
> Fred & I had a little whiteboard session.  The docs indeed
> disagree with the code, and we agree that the code should
> be fixed.  This requires some work: we'll have to introduce a
> new kind of descriptor that wraps a PyMethodDef pointer
> and creates a PyCFunction in response to the p_descr_get
> call with the type as self.  Fred will do this.
Is this still the plan? Fred, are you going to implement this?


----------------------------------------------------------------------

Comment By: Just van Rossum (jvr)
Date: 2002-11-26 05:30

Message:
Logged In: YES 
user_id=92689

This has been open since april, and becomes immediately
relevant with rhettingers dict.fromseq() classmethod
addition: patch #643443. I hadn't seen this bug report
before, but looking at Raymond's code I wondered why cls was
passed as part of args instead of as the first arg of the C
function. I ended up here... I think it's *crucial* this is
fixed before the first alpha of 2.3 is released. Upping the
priority by one...

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2002-05-24 05:53

Message:
Logged In: YES 
user_id=11105

IMO this should be fixed before 2.3 is released, so I'm
raising the priority to 7.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=548651&group_id=5470