suever / pydicom-experimental

pydicom test
0 stars 1 forks source link

UID == x evaluates to true for non-str values of x #96

Closed suever closed 9 years ago

suever commented 9 years ago

From wickedg...@gmail.com on January 14, 2011 20:48:04

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: http://code.google.com/p/pydicom/issues/detail?id=96

suever commented 9 years ago

From darcymason@gmail.com on January 17, 2011 21:40:23

This issue was closed by revision 156044badd .

Status: Fixed