[Ironpython-users] Problem with the "in" operator for

Markus Schaber m.schaber at codesys.com
Tue Jul 7 16:18:30 CEST 2015


Hi,

As far as I can see, the "in" operator should return true if any object in the enumerable is "equal" to the object given as reference:

IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.34209 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> t = (1,2)
>>> o = (t, 3, "4", 1024)
>>> 1024 in o
True
>>> "4" in o
True
>>> (1,2) in o
True
>>> t in o
True
>>> a = 2**100
>>> b = 2**100
>>> a in (b,)
True
>>> a is b
False
>>> import System
>>> g = System.Guid.NewGuid()
>>> h = System.Guid(g.ToString())
>>> g == h
True
>>> g is h
False
>>> g in (h,)
True


However, it looks like this is not working correctly with IDynamicMetaObjectProvider implementations.

I attached an example which is a stripped down case of some much more complex real world code[1]. In that case, the assertion in the last line fails although a equals b.

# a and b are provided by the host written in C#
assert a == b, 'a equals b'
assert not a is b, 'a is not b'

assert a in (a,), 'a is in (a,)'
assert a in (b,), 'a is in (b,)' # this one fails...

As far as I can see via breakpoints, the Equals methods of the objects are never actually called, except on the first assertion with the == operator.

[1] In the real world code, arbitrary plugins may provide extensions to extendable objects from other plugins, to dynamically (at run-time) add methods and properties to those instances.

Best regards

Markus Schaber

CODESYS(r) a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions

3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.schaber at codesys.com | Web: http://www.codesys.com | CODESYS store: http://store.codesys.com
CODESYS forum: http://forum.codesys.com

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Program.cs
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20150707/a2db851d/attachment.ksh>


More information about the Ironpython-users mailing list