[Ironpython-users] bytearray comparison failure

Daniel Fernandez fernandez_dan2 at hotmail.com
Mon Aug 18 23:42:26 CEST 2014


Hi Alex,
Yup I can do that. I also have a fix for translate issue 27904 
I ran the test_bytes.py just to make sure I notice it was failing. In the 
test_zzz_cli_features had this 

AreEqual(bytearray(b'abc') == 'abc', False)

had to change to
AreEqual(bytearray(b'abc') == 'abc', True)
test_translate had this        if is_ironpython: #http://ironpython.codeplex.com/workitem/27904        AssertError(TypeError, bytearray(b'AAA').translate, None, b'A')        AssertError(TypeError, bytearray(b'AAA').translate, None)    else:    replace with just
AreEqual(bytearray(b'AAA').translate(None, b'A'), b'')AreEqual(bytearray(b'AAA').translate(None), b'AAA')
I just commented this out since it doesn't assert.  Should I include the updated test_bytes.py?

After that it passes test_bytes unit test. 
Danny
Date: Mon, 18 Aug 2014 13:51:17 -0700
Subject: Re: [Ironpython-users] bytearray comparison failure
From: slide.o.mix at gmail.com
To: fernandez_dan2 at hotmail.com
CC: ironpython-users at python.org

Can you fork on github and provide a merge request?

On Mon, Aug 18, 2014 at 1:50 PM, Daniel Fernandez <fernandez_dan2 at hotmail.com> wrote:




HI All,
Thanks Alex that was a duh moment for me there. 
I see the issue the code use the as the operator trying to convert to IList<byte>. I simple check if the type is string then convert it to bytes. It works now

Here is the snippet
public override bool Equals(object other) {            IList<byte> bytes ;            if (other is string)                bytes = PythonOps.MakeBytes(((string)other).MakeByteArray());
            else if (other is Extensible<string>)                bytes = PythonOps.MakeBytes(((Extensible<string>)other).Value.MakeByteArray());            else                bytes = other as IList<byte>;


it works now below. 

Dany
Date: Mon, 18 Aug 2014 12:49:04 -0700
Subject: Re: [Ironpython-users] bytearray comparison failure

From: slide.o.mix at gmail.com
To: fernandez_dan2 at hotmail.com
CC: ironpython-users at python.org


ByteArray.cs the Equals method.

On Mon, Aug 18, 2014 at 11:50 AM, Daniel Fernandez <fernandez_dan2 at hotmail.com> wrote:





Hi All,
I ran into an issue comparing bytearray with a string value. I created an issue 35470 on codeplex. The code snippet that can reproduce the issue is

x = bytearray(b'Danny')y = 'Danny'

x == y


IronPython 2.7.5b3 this is False and CPython 2.7.8 is True. 


My question is where in the IronPython code does this happen equality operation occur with different types? I tried to follow it and simple got lost in the maze.  I thought it would occur in the StringOps.Equals but that didn't happen. I tried putting break points all over the place but no luck.


Thanks


Danny





 		 	   		  

_______________________________________________

Ironpython-users mailing list

Ironpython-users at python.org

https://mail.python.org/mailman/listinfo/ironpython-users




-- 
Website: http://earl-of-code.com
 		 	   		  


-- 
Website: http://earl-of-code.com
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140818/84d4810d/attachment.html>


More information about the Ironpython-users mailing list