Repository navigation
Conversation
The dataclass conversion of distutils.extension.Extension used the default eq=True, which generates __eq__ and therefore sets __hash__ to None. Extension instances became unhashable, breaking setup scripts that collect extensions in sets or use them as dict keys (e.g. pywin32 builds). Pass eq=False to lenient_dataclass so Extension keeps the identity-based equality and hashability it had before the conversion. Fixes pypa#5303
Contributor
|
Thank you for the contribution @aryansk . Please have a look on https://setuptools.pypa.io/en/latest/development/developer-guide.html#code-conventions-and-other-practices regarding the There is already pypa/distutils#427 pending of review in the |
Author
|
Thank you for the pointer @abravalheri — you're right that |
anhduc12050820565-web
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5303
Problem
Since v84.0.0,
Extensioninstances are unhashable:The dataclass conversion of the vendored
distutils.extension.Extension(pypa/distutils#373) used the defaulteq=True, which generates__eq__and therefore sets__hash__ = None. Beyond theTypeError, this also silently changed equality semantics: two distinctExtensioninstances with equal field values now compare equal, soext in some_listcan be true for an object that was never appended.Change
Pass
eq=Falsetolenient_dataclassinsetuptools/_distutils/extension.py, restoring the identity-based equality and hashabilityExtensionalways had before the conversion. The lenient unknown-keyword behaviour is unchanged.Note: the same conversion exists upstream in pypa/distutils, so the vendored copy will need this fix re-applied at the next sync unless it lands there first — happy to send that PR if preferred.
Validation
hash()→TypeError,Extension.__hash__ is None) with CPython 3.13; after the change: hashable, distinct instances unequal, usable as set members/dict keys.test_extension_is_hashable);setuptools/_distutils/tests/test_extension.py: 4 passed, 2 skipped (optional mypy inference checks).newsfragments/5303.bugfix.rst).