Skip to content

Conversation

@matthiasdiener
Copy link
Contributor

No description provided.

class WithoutUpdateMethod:
pass

assert keyb(WithoutUpdateMethod) == keyb(WithoutUpdateMethod)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, this should not work. This is a different class every time the function gets called. It might be useful to see if the class type has the same id() as the one available at the advertised name, before using that name for hashing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure I understand. Do you mean, every time test_class_hashing is called, the class is different? But this isn't really tested in this line, perhaps more like in the next line assert keyb(WithoutUpdateMethod) == "da060d601d180d4c"?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean, every time test_class_hashing is called, the class is different?

Yes.

My point is that a function-local class does not have a globally valid name and thus should not be hashable. This can be tested by attempting to import it by its __qualname__ (won't work for local classes) and seeing if it comes back with the same id (just to be safe).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, thanks! What do you think of e35c58a? I'm worried that this may cause extra cache misses since some tags that we use might be local classes?

)
else:
# Name collision or local class; fall back
self.rec(key_hash, f"{key.__module__}.{key.__qualname__}_{id(key)}")
Copy link
Owner

@inducer inducer Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think local classes should be unhashable, i.e. this should be an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants