'class' argument optional for new.instancemethod?

M

Martin Miller

In section "3.27 new -- Creation of runtime internal objects" of the
documentation that comes with Python 2.4 it says:
instancemethod(function, instance, class)

This function will return a method object, bound to instance, or unbound if
instance is None. function must be callable.

However, some simple experiments I've tried seem to indicate that the
last argument, 'class' can be left off with no ill effects, and is
therefore optional.

Doesn't anyone know if this is a documention problem? Personally, I
don't understand how the argument gets used when it *is* provided -- if
nothing else, having it seems somewhat redundant given the presence of
the 'instance' argument.

TIA,
Martin
 
P

Peter Hansen

Martin said:
In section "3.27 new -- Creation of runtime internal objects" of the
documentation that comes with Python 2.4 it says:
instancemethod(function, instance, class)
[...]
However, some simple experiments I've tried seem to indicate that the
last argument, 'class' can be left off with no ill effects, and is
therefore optional.

Doesn't anyone know if this is a documention problem? Personally, I
don't understand how the argument gets used when it *is* provided -- if
nothing else, having it seems somewhat redundant given the presence of
the 'instance' argument.

A little experimentation reveals at least one thing that
argument affects:
.... pass
........ pass
........ print 'in f', self
....<bound method ?.f of <__main__.A instance at 0x00AE5EB8>>

So without the class argument, at least in this small
sample, the bound method doesn't know what class
it belongs to, at least for purposes of printing
it's own repr().

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top