Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33941

Re: How to pass class instance to a method?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!zen.net.uk!dedekind.zen.co.uk!reader02.nrc01.news.zen.net.uk.POSTED!not-for-mail
From Nobody <nobody@nowhere.com>
Subject Re: How to pass class instance to a method?
Date Mon, 26 Nov 2012 16:56:15 +0000
User-Agent Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)
Message-Id <pan.2012.11.26.16.56.29.389000@nowhere.com>
Newsgroups comp.lang.python
References <3193e3dd-0507-4ff7-9026-ee80e5d9c1dd@googlegroups.com>
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Lines 28
Organization Zen Internet
NNTP-Posting-Host 56ebf272.news.zen.co.uk
X-Trace DXC=^:Phfm@RP0D;dNhMZVkA7F]G;bfYi23hD=dR0\ckLKG@WeZ<[7LZNRF8VJhX0JL0@GNQ<`Sf8^TaOd60moJ\ihlJ@__W9[:iOAF
X-Complaints-To abuse@zen.co.uk
Xref csiph.com comp.lang.python:33941

Show key headers only | View raw


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?

Python isn't statically typed. You can explicitly check for a specific
type with e.g.:

	if not isinstance(arg, SomeType):
	    raise TypeError('expected SomeType but got %s' % type(arg))

But this defeats duck typing. If you do this a lot, you're using the wrong
language.

> I suppose there shall be some kind of method decorator to treat an
> argument as an instance of class?
> 
> Generally it is needed so IDE (PyCharm) can auto-complete instance's
> methods and properties.

You have it backwards.

In a dynamically-typed language such as Python, the set of acceptable
types for an argument is determined by the operations which the function
performs on it. This is in direct contrast to a statically-typed language,
where the set of acceptable operations on an argument is determined by the
type of the argument.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to pass class instance to a method? ALeX inSide <alex.b.inside@gmail.com> - 2012-11-25 04:11 -0800
  Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-25 12:37 +0000
  Re: How to pass class instance to a method? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2012-11-26 11:22 +1300
  Re: How to pass class instance to a method? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-11-26 11:08 +0100
  Re: How to pass class instance to a method? Nobody <nobody@nowhere.com> - 2012-11-26 16:56 +0000
    Re: How to pass class instance to a method? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-26 13:51 -0700
    Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 16:58 -0500
      Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-26 22:18 +0000
        Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 22:14 -0500
          Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-27 04:10 +0000
            Re: How to pass class instance to a method? Roy Smith <roy@panix.com> - 2012-11-26 23:25 -0500
            Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-27 00:18 -0500
    Re: How to pass class instance to a method? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-26 16:07 -0700
      Re: How to pass class instance to a method? Hans Mulder <hansmu@xs4all.nl> - 2012-11-27 01:36 +0100
    Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 21:50 -0500
  Re: How to pass class instance to a method? Drew <r.drew.davis@gmail.com> - 2012-11-26 17:14 -0800

csiph-web