How to pass class instance to a method?
Dave Angel
d at davea.name
Mon Nov 26 21:50:00 EST 2012
On 11/26/2012 06:07 PM, Ian Kelly wrote:
> On Mon, Nov 26, 2012 at 2:58 PM, Dave Angel <d at davea.name> wrote:
>> Not how I would put it. In a statically typed language, the valid types
>> are directly implied by the function parameter declarations,
> As alluded to in my previous post, not all statically typed languages
> require parameter type declarations to perform static checking.
>
>> while in a
>> dynamic language, they're defined in the documentation, and only
>> enforced (if at all) by the body of the function.
> That's not even true for Python. The following example uses Python 2.x:
>
>>>> class Foo(object):
> ... def method(self):
> ... pass
> ...
>>>> Foo.method(4)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: unbound method method() must be called with Foo instance as
> first argument (got int instance instead)
>
> That's a run-time check, and it's not enforced by the body of the function.
We were talking about function arguments. I don't know of any place
where they get their types declared.
--
DaveA
More information about the Python-list
mailing list