Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected results when comparing two untangle.Element objects with the == operator #63

Open
amorimlb opened this issue Aug 8, 2019 · 2 comments
Labels

Comments

@amorimlb
Copy link

amorimlb commented Aug 8, 2019

Recently I had to check whether an item in a list of untangle.Element was inside a second list using the in operator. Turns out the result was very misleading:
Note: I know I shouldn't initialise an untangle.Element object like this (in my real life code I am using untangle.parse('file.xml') which creates a list of various untangle.Element), but this is the smallest syntactically correct code I could supply for this illustration.

import untangle
a = untangle.Element('a', '1')
b = untangle.Element('b', '1')
listA = [a, b]
c = untangle.Element('c', '1')
print(c in listA)

This prints True, but should print False as it does in:

a = object()
b = object()
listA = [a, b]
c = object()
print(c in listA)

So, since the in operator uses == to compare items, I thought it could be a problem with how == is being implemented in the Element class, which I think I confirmed by running:

import untangle
a = untangle.Element('a', '1')
b = untangle.Element('b', '1')
print(a == b)

This prints out True, but should print False, as this other code does:

a = object()
b = object()
print(a == b)

Using Python 3.6.8 and untangle 1.1.1
@adijbr contributed to these tests and bug report.
Thanks!

stchris added a commit that referenced this issue Nov 18, 2019
stchris added a commit that referenced this issue Nov 18, 2019
@stchris
Copy link
Owner

stchris commented Nov 18, 2019

You are right about this. The problem stems from the fact that untangle tries to be clever, so you can say object.attribute == "Foo".

I will have to think about how to fix this, if it is even possible without major breaking changes.

@stchris stchris added the bug label Nov 18, 2019
@amorimlb
Copy link
Author

amorimlb commented Dec 2, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants