[Python-Dev] Classmethod Help

Just van Rossum just@letterror.com
Fri, 29 Nov 2002 13:53:57 +0100


Armin Rigo wrote:

> On Mon, Nov 25, 2002 at 06:07:05PM -0500, Raymond Hettinger wrote:
> > GvR pointed me to you guys for help in the C 
> > implementation of the patch for a dictionary class method:
> 
> There are METH_CLASS and METH_STATIC flags that you can set in the
> tp_methods table.
> 
> By the way, in your example you don't use the 'cls' parameter, so this
> looks like a static method rather than a class method, right?

Seems you're looking at an earlier patch: it's already in CVS and it does use
cls now.

I have a different comment about this patch, though. It's currently possible to
trigger a "SystemError: bad internal call" with Python code:

  >>> from UserDict import UserDict
  >>> class mydict(dict):
  ...     def __new__(cls, *args, **kwargs):
  ...         return UserDict(*args, **kwargs)
  ... 
  >>> set = mydict.fromkeys("a b c".split())
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  SystemError: ../Objects/dictobject.c:983: bad argument to internal function
  >>> 

It's not a particularly sane piece of code, and I'm not saying the code should
_work_, but I'm not so sure a SystemError is appropriate here.

Just