[Python-Dev] why different between staticmethod and classmethod on non-callable object? (original) (raw)
xiaobing jiang s7v7nislands at gmail.com
Tue Sep 1 05:47:44 CEST 2009
- Previous message: [Python-Dev] default of returning None hurts performance?
- Next message: [Python-Dev] why different between staticmethod and classmethod on non-callable object?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
hi all: In the svn thunk tree, I find in file Object/funcobject.c, the two functions: sm_init and cm_init have a little different. the cm_init function will check the object is really callable, but the sm_init don't. the code like this: if (!PyCallable_Check(callable)) { PyErr_Format(PyExc_TypeError, "'%s' object is not callable", callable->ob_type->tp_name); return -1; }
so when use staticmethod and classmethod on a class variable, there are two different behavior.
class Test(object): name = "s7v7nislands"
name = classmethod(Test.name) # will raise error. name = staticmethod(Test.name) # will not raise error.
My idea is: here, the two functions (or maybe classes) should have the same behavior). so is this a bug or something I missing ?
thanks!
s7v7nislands
- Previous message: [Python-Dev] default of returning None hurts performance?
- Next message: [Python-Dev] why different between staticmethod and classmethod on non-callable object?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]