[Patches] [ python-Patches-418390 ] static member functions
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 23 Apr 2001 16:00:26 -0700
Patches item #418390, was updated on 2001-04-23 15:39
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=418390&group_id=5470
Category: core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: static member functions
Initial Comment:
This allows for class methods to be called statically
without the need for workaround abuse as described in
the python FAQ (or any other method involving grabbing
the "im_func" member from an unbound method object).
This patch changes the "call_method" function in
ceval.c. It removes the improper 'class type
enforcement' on unbound method objects and just passes
the arguments as is.
This allows for natural and clean static methods
inside classes.
The only thing potentially broken with this patch is a
looser guarantee that the "self" value for a method
would be some inherited type instance. This is far
less 'dangerous for abuse' than other python class
designs (no private members, etc).
With this the static method example in the FAQ is much
more cleanly realized. notice, no "self" member for
static methods...
class C:
count = 0
def __init__(self):
C.count += 1
def getcount():
return C.count
def sum(x, y):
return x + y
C(); C()
c = C()
print C.getcount() # prints 3
print c.getcount() # prints 3
print C.sum(27, 15) # prints 42
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2001-04-23 16:00
Message:
Logged In: NO
btw, i did submit with my email address, but sourceforge
has relabeled me as anonymous. please respond to
"pete at shinners dot org"
should that be required. doh, i see sourceforge didn't
respect my example formatting either.
----------------------------------------------------------------------
Comment By: Mark Kimsal (hardcoreholly)
Date: 2001-04-23 15:47
Message:
Logged In: YES
user_id=89302
an application programmer could still secure the type of
the arguments if s/he felt it was necessary by raising the
unbound method exception if the first arg was not the
expected type.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=418390&group_id=5470