Skip to content

Hashability follow-ups: equal-objects-equal-hash test, and static: dict[str, Any] can silently reintroduce unhashability #30

Description

@jeqcho

Follow-up to #26, which gave TaskInstance and Realization custom __hash__ methods (sorted item tuples over their dict fields).

Two gaps worth closing:

  1. test_instances_and_realizations_are_hashable only hashes the same object reference and checks x in {x}, which passes even under identity hashing. The invariant the fix actually establishes, equal objects hash equal, is untested: construct two independent but ==-equal instances, assert hash(a) == hash(b) and {a: 'x'}[b] == 'x'. Without it, a future simplification back toward default hashing slips through green CI.

  2. TaskInstance.static is typed dict[str, Any]. Every current spec stores only strings, but nothing stops a future spec from putting a list in there, which would make __hash__ raise TypeError again with no test to catch it. Either tighten the annotation to the hashable subset actually used, or document the invariant next to the field and add a spec-wide test that hash() succeeds for every entry in SPECS (the latter already half-exists and would catch it at test time).

Both are small and self-contained.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions