I have a weird situation. I have a dict, self.containing_dict. Using the debug probe, I see that dict's contents and I can see that self is a key of it. But look at this:
>>> self in self.containing_dict False >>> self in self.containing_dict.keys() True >>> self.containing_dict.has_key(self) False What's going on?
(I will note that this is in a piece of code which gets executed on a weakref callback.)
Update: I was asked to show the __hash__ implementation of self. Here it is:
def __hash__(self): return hash( ( tuple(sorted(tuple(self.args))), self.star_args, tuple(sorted(tuple(self.star_kwargs))) ) ) args = property(lambda self: dict(self.args_refs)) star_args = property( lambda self: tuple((star_arg_ref() for star_arg_ref in self.star_args_refs)) ) star_kwargs = property(lambda self: dict(self.star_kwargs_refs))
self? Does it have an__eq__redefined?self.containing_dictjust a Pythondictor something like aweakref.WeakKeyDictionary? If the former, are keys or values of the dict themselves weakrefs?has_keyis deprecated - docs.python.org/library/stdtypes.html#dict.has_key - so maybe you should just not worry about it. :-)dict.