Skip to content

Collections: Preserve container types when normalizing - #5862

Open
aliassar wants to merge 3 commits into
robotframework:masterfrom
aliassar:fix-normalize-preserve-hashable
Open

aliassar wants to merge 3 commits into
robotframework:masterfrom
aliassar:fix-normalize-preserve-hashable

Conversation

@aliassar

@aliassar aliassar commented Nov 18, 2026 •

Copy link
Copy Markdown

Since #5859, keys are also normalized with ignore_case=VALUES and values with ignore_case=KEYS. _try_to_preserve_type() can't rebuild namedtuples or ranges with cls(list), so they became lists, which made such dict keys unhashable and made such values compare equal to lists. This leaves ranges alone (they only contain integers, so there's nothing to normalize) and rebuilds namedtuples with _make; lists and other containers are handled exactly as before, and #5858's tests still pass.

Side effects, also in BuiltIn keywords using ignore_case, strip_spaces or collapse_spaces: ranges and namedtuples no longer compare equal to lists, which matches comparing without normalization and how plain tuples already behave. Ranges are also no longer sorted with ignore_order (ignore_value_order in Collections), so range(2) and range(1, -1, -1) are now reported as different.

Fixes #5861.

Containers that normalization does not change are now returned as-is
and namedtuples are recreated using `_make`. Earlier they could be
converted to lists, which made namedtuple and range keys unhashable
with `ignore_case=VALUES` and made such values equal to lists with
`ignore_case=KEYS`.

Fixes robotframework#5861.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 19:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Normalization shortcuts break order-insensitive comparisons of equivalent ranges and discard case-normalized Counter keys inside tuples.

2 open issues
What changed in this PR

This PR addresses container-type regressions introduced by recursive case normalization in Collections. It preserves unchanged hashable sequences and rebuilds namedtuples without converting them to lists.

Changes:

  • Preserve unchanged hashable sequences and reconstruct namedtuples with _make.
  • Add regression cases for hashable dictionary keys and range-versus-list value comparisons.
  • Register the new cases in the acceptance-test verification suite.
File Description
src/​robot/​libraries/​normalizer.py Preserve sequence types during normalization.
atest/​testdata/​standard_libraries/​collections/​dictionaries_should_be_equal.robot Add container-preservation regression cases.
atest/​robot/​standard_libraries/​collections/​dictionaries_should_be_equal.robot Verify the new acceptance cases.

Review effort: Balanced

Comment thread src/robot/libraries/normalizer.py Resolved
Comment thread src/robot/libraries/normalizer.py Resolved
…e_order

Unchanged containers are now detected by item identity only. Equality
can hide normalization changes, for example `Counter({'A': 0})` equals
`Counter({'a': 0})`, which caused case differences inside tuples to be
reported. With `ignore_order`, values are always sorted and rebuilt
like earlier, so equivalent ranges in a different order compare equal.

Related to robotframework#5861.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Sequence normalization can still convert ranges into lists and reconstruct namedtuples when ignoring order, causing unhashable dictionary keys and comparison regressions.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Skip namedtuple reconstruction when ignoring order

src/​robot/​libraries/​normalizer.py:118

The new _make path also runs when ignore_order is enabled, changing the existing sorted-list fallback for namedtuples. With Pair = namedtuple('Pair', 'x y'), dictionaries_should_be_equal({'item': Pair(2, 1)}, {'item': [1, 2]}, ignore_value_order=True) previously passed but now compares Pair(1, 2) against [1, 2] and fails. Skip namedtuple reconstruction when ignoring order to retain the sorting behavior promised in the PR description, and add this mixed-container regression case.

2 resolved since last review

Review effort: Balanced

Comment thread src/robot/libraries/normalizer.py Resolved
Ranges only contain integers that normalization cannot change, so they
are now returned as-is. This keeps them hashable regardless of the size
of the integers. The earlier identity based check failed with ranges
like `range(1000, 1002)` because iterating them creates new integer
objects. That check is not needed anymore and has been removed.

As a small functional change, ranges are not sorted with `ignore_order`
anymore.

Related to robotframework#5861.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the container-type preservation changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Collections: recursive case normalization can make dictionary keys unhashable

3 participants