How to pass class instance to a method?

Alain Ketterlin alain at
Mon Nov 26 11:08:37 CET 2012

ALeX inSide <alex.b.inside at> writes:

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

Python does not do static typing.

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

Decorators are an option. Another is the use of the new parameter
annotations (param : expr) in function/method parameters. (That's python
3, not 2).

> Generally it is needed so IDE (PyCharm) can auto-complete instance's
> methods and properties.

You can't expect static info on the class of the object referenced by
any name, unless you impose strong conventions on the code.

> 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

Could: xxx(self,myclass : MyClass, ...)

-- Alain.

More information about the Python-list mailing list