Skip to content

Restore hashability of Extension via eq=False (fix #5303) - #5349

Open
inchang-ing wants to merge 1 commit into
pypa:mainfrom
inchang-ing:fix/extension-hashable-5303
Open

inchang-ing wants to merge 1 commit into
pypa:mainfrom
inchang-ing:fix/extension-hashable-5303

Conversation

@inchang-ing

Copy link
Copy Markdown

Description

setuptools.extension.Extension became unhashable in 84.0.0: the dataclass conversion used the default eq=True, which generates __eq__ and therefore forces __hash__ to None. Setup scripts that collect extensions in sets or use them as dict keys break outright (e.g. every pywin32 CI build currently fails with TypeError: unhashable type: 'WinExt_pythonwin').

This passes eq=False to the lenient_dataclass decorator, so Extension keeps its historical identity-based equality and hash instead of gaining value equality.

Fix

  • setuptools/_distutils/extension.py: @lenient_dataclass() → @lenient_dataclass(eq=False).

Verification

  • Regression tests added in setuptools/_distutils/tests/test_extension.py (test_extension_is_hashable, test_extension_hash_survives_set_membership).
  • Discriminate: reverting the decorator to eq=True makes test_extension_is_hashable fail with TypeError: unhashable type: 'Extension'; with the fix it passes.

Fixes #5303

The dataclass conversion introduced in 84.0.0 generated __eq__ and
therefore set __hash__ to None, making setuptools.extension.Extension
unhashable and breaking setup scripts that collect extensions in sets
or use them as dict keys (e.g. pywin32 CI builds). Pass eq=False to the
lenient_dataclass decorator so Extension keeps its historical
identity-based equality and hash.

Fixes pypa#5303
@mergify

mergify Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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.

[BUG] 84.0.0: Extension is unhashable (dataclass conversion sets __hash__ = None) — breaks setup scripts using sets of extensions

1 participant