Skip to content

fix: Make map.Map and maptree.MapTree require keys to be hashable - #258

Merged
dbrattli merged 5 commits into
dbrattli:mainfrom
jonathandung:patch-1
Aug 15, 2026
Merged

fix: Make map.Map and maptree.MapTree require keys to be hashable#258
dbrattli merged 5 commits into
dbrattli:mainfrom
jonathandung:patch-1

Conversation

@jonathandung

Copy link
Copy Markdown
Contributor

Seeing as though the map.Map class implements the Mapping interface, the type variable used to annotate its keys should require hashability, and the same goes for maptree.MapTree, used internally by the above only.

@jonathandung

Copy link
Copy Markdown
Contributor Author

Parent: python/typeshed#15754

@dbrattli dbrattli left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the typeshed-alignment proposal. Before this can be reviewed for merge, please rebase onto the current main (the branch is nine commits behind) and add focused type-check coverage demonstrating that comparable-but-unhashable keys are rejected while standard ordered, hashable keys remain accepted. Please also simplify the new protocol implementation to a declaration-only member (...) rather than calling super().__hash__(); the protocol is structural and has no meaningful runtime implementation.

@dbrattli dbrattli left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approved. The hashable key bound correctly aligns Map with the Mapping contract and its existing use of key hashing. My previous request reflected integration preferences rather than a design blocker; a maintainer update/rebase can be handled as part of merge preparation.

@dbrattli dbrattli changed the title Make map.Map and maptree.MapTree require keys to be hashable fix: Make map.Map and maptree.MapTree require keys to be hashable Aug 15, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dbrattli

Copy link
Copy Markdown
Owner

Fixed the strict Pyright failures in abf8370 by restoring MapTree.empty and size to key-agnostic internal annotations. The public Map/MapTree key bound remains comparable-and-hashable; Pyright, Map tests, and Ruff pass.

@dbrattli
dbrattli merged commit 8c19a1b into dbrattli:main Aug 15, 2026
7 checks passed
@jonathandung
jonathandung deleted the patch-1 branch August 16, 2026 03:46
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