logo       

Re: Null reference: msg#00160

programming.swig

Subject: Re: Null reference

On 2003.11.26 10:19, renz@xxxxxxxxxxxxxxxx wrote:
Well, there will be no error occurred, if == is not defined for class
v. None in (mod.v(1), None) returns 1.

That's because the default behavior is to compare identity.

I thought it should not compare equality, instead it should compare identity.

It does by default. But when you define an operator== (or either __eq__ or __cmp__ in Python) you're explicitly specifying that you want to override that behavior. That's not SWIG-specific---look at the following pure Python.

class Foo:
... def __eq__(self,x):
... if x is None:
... raise Exception("ni!")
...
None in [ Foo(), None ]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 4, in __eq__
Exception: ni!


You can't blame Python for not disregarding what you tell it.

Cheers,
Luigi
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise