[Python-bugs-list] [ python-Bugs-454887 ] static/classmethods and tp_slots

noreply@sourceforge.net noreply@sourceforge.net
Tue, 04 Sep 2001 21:16:33 -0700


Bugs item #454887, was opened at 2001-08-24 01:36
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=454887&group_id=5470

Category: Type/class unification
Group: Python 2.2
>Status: Closed
Resolution: None
Priority: 4
Submitted By: Roeland Rengelink (rengelink)
Assigned to: Guido van Rossum (gvanrossum)
Summary: static/classmethods and tp_slots

Initial Comment:
Consider:

>>> class D(object):
...     def __iter__():return iter([1,2,3])
...     __iter__ = staticmethod(__iter__)
... 
>>> D.__iter__()
<iterator object at 0x814cfcc>
>>> iter(D)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: iter() of non-sequence

I can't say this is a bug, because i don't think the
behaviour of assignment of staticmethod and classmethod
objects to tp_* slots is defined. However, the
behaviour was unexpected to me.  Also, if the
assignment is illegal it should probably raise an error
at class definition time.

PS I have one or two similar examples of surprising
errors that would probably just need additional docs to
explain them. Should I report these as bugs, or should
I await further releases/doc updates first?

Cheers,

Roeland

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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-04 21:16

Message:
Logged In: YES 
user_id=6380

No further response, assume no further action needed.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-24 02:42

Message:
Logged In: YES 
user_id=6380

This is indeed as intended. To get the behavior you want
(iterate over a class object) you would have to define a
metaclass (derived from type) that defines __iter__.

I'll try to ensure this is documented.

I disagree that the assignment is illegal: in general if you
put something invalid in a special method name it's very
hard to detect that until the time you actually try to call
it.

Why don't you email me the other examples?

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

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