Skip to content

tests: fix accelerator_parse hash mismatch on Python 3.14 - #1092

Merged
mattrose merged 1 commit into
gnome-terminator:masterfrom
blshkv:fix-accelerator-parse-hash-python314
Jun 3, 2026
Merged

mattrose merged 1 commit into
gnome-terminator:masterfrom
blshkv:fix-accelerator-parse-hash-python314

Conversation

@blshkv

@blshkv blshkv commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1089

Gtk.accelerator_parse() returns a gi._gi.ResultTuple, a subclass of tuple that has __hash__ hardcoded to 0. Plain Python tuples use content-based hashing.

This breaks set membership checks in two tests:

all_default_accelerators = {
    Gtk.accelerator_parse(accel)   # ResultTuple, hash=0
    ...
}
assert (key, mods) in all_default_accelerators  # plain tuple, hash≠0 → always False

Even though ResultTuple == plain_tuple returns True, Python set lookup first checks the hash bucket. Since hash(plain_tuple) != 0 in general, the element is never found.

Fix

Wrap Gtk.accelerator_parse() with tuple() in both affected set/list comprehensions so all objects share the same hash implementation:

all_default_accelerators = {
    tuple(Gtk.accelerator_parse(accel))
    ...
}

Affected tests

  • test_non_empty_default_keybinding_accels_are_distinct
  • test_duplicate_accels_not_possible_to_set

gi._gi.ResultTuple (returned by Gtk.accelerator_parse()) has __hash__
hardcoded to 0, while plain tuples use content-based hashing. This
breaks set membership checks: (key, mods) in {ResultTuple(...)} fails
even though equality holds, because Python set lookup uses hash first.

Fix: wrap Gtk.accelerator_parse() calls with tuple() so both the set
contents and the lookup key share the same hash implementation.

Fixes: #1089
blshkv added a commit to blshkv/pentoo-overlay that referenced this pull request Jun 3, 2026
Gtk.accelerator_parse() returns gi._gi.ResultTuple which has __hash__
hardcoded to 0, while plain tuples have a proper content-based hash.
This breaks set membership checks when comparing ResultTuple against
a plain (key, mods) tuple even though == returns True.

Fix: wrap Gtk.accelerator_parse() results with tuple() in the two
affected set comprehensions in test_prefseditor_keybindings.py.

Upstream PR: gnome-terminator/terminator#1092
Bug: gnome-terminator/terminator#1089
@mattrose

mattrose commented Jun 3, 2026

Copy link
Copy Markdown
Member

Given that the same tests pass in my test environment where I try to match the conditions described in the issue I'm hesitant to pull in this fix. If you could describe the environment and conditions in which the tests fail so that I can ensure the tests fix this, I would appreciate it. Maybe it has a newer version of Gtk that behaves differently?

@mattrose

mattrose commented Jun 3, 2026

Copy link
Copy Markdown
Member

Found an environment where the issue could be reproduced. Testing fix now

@mattrose
mattrose merged commit c5e50d4 into gnome-terminator:master Jun 3, 2026
1 check passed
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.

Unit test fails on python 3.14

2 participants