Kalle Anke wrote:
> On Sun, 12 Jun 2005 13:59:27 +0200, deelan wrote
> (in article <[EMAIL PROTECTED]>):
> 
> void doSomething( data : SomeClass ){ ... }
> 
> and I would be sure at compile time that I would only get SomeClass objects 
> as parameters into the method.

Being an untyped language, Python does not require you to enforce types. 
However, for those that require such functionality, you can get away 
with using the "assert" statement. For example, if I wanted to make sure 
my function foo was only given instances of class Bar, I'd write 
something like:

 >>> class Bar: pass
 >>> def foo(bar):
...     assert isinstance(bar, Bar), "argument is not of type Bar"
...     print "argument must be of type Bar"
...
 >>> bar = Bar()
 >>> foo(bar)
argument must be of type Bar
 >>> foo(123)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "<stdin>", line 2, in foo
AssertionError: argument is not of type Bar
 >>>

Chris
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to