[Python-bugs-list] [ python-Bugs-668980 ] classmethod does not check its arguments

SourceForge.net noreply@sourceforge.net
Tue, 01 Jul 2003 20:52:16 -0700


Bugs item #668980, was opened at 2003-01-16 05:22
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=668980&group_id=5470

Category: Type/class unification
Group: None
Status: Open
Resolution: None
Priority: 1
Submitted By: Martin v. Löwis (loewis)
>Assigned to: Martin v. Löwis (loewis)
Summary: classmethod does not check its arguments

Initial Comment:
In 2.3a1, classmethod(3) works just fine. I think it
should be a type error.

It might be worthwhile to specialcase method objects,
so that

class X:
  def foo(self):pass

X.foo=classmethod(X.foo)

does the "right" thing, i.e. is equivalent to

class X:
  def foo(self):pass
  foo=classmethod(foo)

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

>Comment By: Neal Norwitz (nnorwitz)
Date: 2003-07-01 23:52

Message:
Logged In: YES 
user_id=33168

classmethod(3) does raise a TypeError in 2.3b2.  Should this
be closed?

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-01-16 09:52

Message:
Logged In: YES 
user_id=6380

Not convinced; there are subtle things you might want to do
with classmethod (and staticmethod) that a type check would
prevent.

I could live with something that checks whether the argument
is callable.

There are definitely some weird things:

>>> C.x = classmethod(12)
>>> C.x()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
SystemError: ../Objects/classobject.c:2081: bad argument to
internal function
>>>

vs.

>>> C.x = staticmethod(12)
>>> C.x()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'int' object is not callable
>>> 

Anyway I have bigger fish to fry for now.

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

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