Edward Pilatowicz wrote: > i did this because if you have an Action object and you try doing: > > if src != None: > > then you'll get an exception: > > ---8<--- > File > "/export/ws/pkg.pkgplan_cleanup/proto/root_i386/usr/lib/python2.6/vendor-packages/pkg/actions/generic.py", > line 431, in __ne__ > if self.name == other.name and \ > AttributeError: 'NoneType' object has no attribute 'name' > ---8<--- > > because the __ne__() function for action objects assumes your comparing > the current action against another action (and not some other type of > object). > > so i changed all getstate() and setstate() code to use: > > type(XXX) != type(None) > > because that makes the comparison independent of any __ne__() > implementation in the class your comparing against (and for consistency, > i did this for all the "None" comparisons in the *state()). if you'd > like me to do this some other way then just let me know what's > preferable.
Why not simply have __ne__() in the generic action class do the comparison against None, and return True if so? Probably want an equivalent test in __eq__() as well. Or you could test with isinstance(), as in __cmp__(), though in that case you'd want to return True or False instead of NotImplemented. All of this should be performance tested, regardless. And if you're comparing against None, then you're better off comparing using the "is" operator, which would sidestep this issue entirely, as well as be more performant. Besides (I'm just looking at your second webrev's pkgplan code now), why are you comparing against type(None) instead of isinstance(basestring), since the only valid input to fromstr() is a string? Danek _______________________________________________ pkg-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
