How to pass class instance to a method?

Steven D'Aprano steve+comp.lang.python at
Sun Nov 25 13:37:35 CET 2012

On Sun, 25 Nov 2012 04:11:29 -0800, ALeX inSide wrote:

> How to "statically type" an instance of class that I pass to a method of
> other instance?

Please explain what you mean by this.

What do you think "statically type" means?

> I suppose there shall be some kind of method decorator to treat an
> argument as an instance of class?

Python does not allow you to lie about the type of an argument. All 
objects are strongly typed. If an object is a Spam instance, it is a Spam 
instance, you can't pretend that it is a Cheese instance.[1]

> Generally it is needed so IDE (PyCharm) can auto-complete instance's
> methods and properties.
> Pseudo-python-code example:
> i = MyClass()
> xxx(i, 1, 2);
> ...
> def xxx(self, MyClass myclass, number, foobar):
>    myclass.classsmethod() #myclass - is an instance of known class

I do not understand what you are saying here. Please try to explain more 

[1] You cannot lie about the type of an instance, but sometimes you can 
actually change its type. Use this feature with care, since it rarely is 


More information about the Python-list mailing list