Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1068751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:19:37+00:00 2026-05-16T20:19:37+00:00

I have a weird situation. I have a dict, self.containing_dict . Using the debug

  • 0

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))    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:19:38+00:00Added an answer on May 16, 2026 at 8:19 pm

    The problem you describe can only be caused by self having implemented __eq__ (or __cmp__) without implementing an accompanying __hash__. If you didn’t implement a __hash__ method, you should do so — normally you can’t use objects that define __eq__ but not __hash__ as dict keys, but if you inherit a __hash__ that may slip by.

    If you do implement __hash__, you have to make sure it acts the right way: the result must not change over the lifetime of the object (or at least as long as the object is in use as a dict key or set item), and it must be consistent with __eq__. An object’s hash value must be the same as objects it’s equal to (according to its __eq__ or __cmp__.) An object’s hash value may be different from objects it’s not equal to, but it doesn’t have to be. The requirements also mean you can not have the result of __eq__ change over the lifetime of the object, which is why mutable objects usually can’t be used as dict keys.

    If your __hash__ and __eq__ are not matched up, Python won’t be able to find the object in dicts and sets, but it will still show up in dict.keys() and list(set), which is what you’re describing here. The usual way to implement __hash__ methods is by returning the hash() of whatever attributes you use in your __eq__ or __cmp__ method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have a weird situation. I'm using Glassfish server for my Enterprise application. In that
I have a weird date rounding problem that hopefully someone can solve. My client
Howdy all, I have a weird situation. I have a C++ code that overloads
I have this weird situation where my form doesn't send any data, but the
I have a weird issue that only seems to be affecting IE 7. The
I have some extremely weird behavior that seems to result in silent exceptions. How
I have a weird situation where I open a form from my application, hide
I have a weird situation where a modal popup gets hidden automatically when it
I have a weird situation involving the need of a double inner join. I
I have a weird situation with my sharepoint css. It is deployed as part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.