Deriving from builtin types with limited instances and Extending FAQ 6.6

Alex Martelli aleax at aleax.it
Sun Feb 9 10:19:41 EST 2003


Gerrit Holl wrote:
   ...
>  >>> class A(iter): pass
>  ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: cannot create 'builtin_function_or_method' instances
> 
> This one doesn't work either. The error message seems reasonable,
> becuase 'class A(map)' won't work either. However, what is exactly
> the difference with 'class A(int)'? I can also try:

>>> type(iter)
<type 'builtin_function_or_method'>
>>> type(map)
<type 'builtin_function_or_method'>
>>> type(int)
<type 'type'>
>>> type(list)
<type 'type'>
>>>

This is exactly the difference: you can inherit from a TYPE (if
that type is designed to allow inheritance, and says so among
the flags in its C-level structure) but you can never inherit 
from a FUNCTION.


Alex





More information about the Python-list mailing list