Python 2.7 (r27:82508, Jul 3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dicom
>>> u = dicom.UID.UID('1.2.840.10008.1.2.4.50')
>>> u
'1.2.840.10008.1.2.4.50'
>>> u == 3
True
>>> u == None
True
This is due to how the UID.__eq__ function uses str.__eq__:
>>> str.__eq__(u, None)
NotImplemented
>>> print type(str.__eq__(u, None))
<type 'NotImplementedType'>
>>> bool(NotImplemented)
True
Using str(u) == None gives the expected answer of False. I think that using
'is True' in the comparison function will work:
def __eq__(self, other):
"""Override string equality so either name or UID number match passes"""
if str.__eq__(self, other) is True:
return True
if str.__eq__(self.name, other) is True:
return True
return False
That could be shortened to:
return str.__eq__(self, other) is True or str.__eq__(self.name, other) is True
I'm not 100% certain that either of those handle all cases, though.
Original issue reported on code.google.com by wickedg...@gmail.com on 15 Jan 2011 at 1:48
Original issue reported on code.google.com by
wickedg...@gmail.com
on 15 Jan 2011 at 1:48