Home

"sebastien.lannez@gmail.com" <sebastien.lannez@gmail.com> writes:

> I need to overload the operator in and let him return an object
> ... It seems it is not a behavior Python expect :

Python expects it all right, but it intentionally converts the value
to a boolean. The 'in' operator calls PySequence_Contains, which
returns a boolean value at the C level. User-supplied __contains__ is
implemented as an adaptor in typeobject.c (slot_sq_contains). It
takes the value returned by your __contains__ implementation and
converts it to 0 or 1.

I don't think you can overload 'in' as you want without pervasive
changes to CPython source code.

previous
next

Why 'class spam(object)' instead of class spam(Object)' ?
Re: How can I replace all occurrences of a character with another character in std string?
Re: Enums
Re: Top Programming Languages of 2013
Re: Getting the result of a process after exec*()
Mimo Wszystko
Mam Marzenie
Fundacja Hobbit
Pajacyk
Rodzic Po Ludzku