Skip to content

gh-94107: Make _pydecimal.Context hashable to match _decimal.Context - #158160

Open
nirajan-khatiwada wants to merge 2 commits into
python:mainfrom
nirajan-khatiwada:fix-pydecimal-context-hash-gh-94107
Open

nirajan-khatiwada wants to merge 2 commits into
python:mainfrom
nirajan-khatiwada:fix-pydecimal-context-hash-gh-94107

Conversation

@nirajan-khatiwada

Copy link
Copy Markdown

Summary of Changes

In _decimal.Context, instances are hashable via object.__hash__, but _pydecimal.Context explicitly disabled hashing with __hash__ = None. Under PEP 399, pure-Python fallback implementations must match the behavior of accelerated C modules.

As discussed in issue #94107 by @rhettinger and @mdickinson, this PR removes __hash__ = None in _pydecimal.Context so that it inherits object.__hash__, matching _decimal.Context.

  • Removed __hash__ = None from _pydecimal.Context.
  • Added test_context_hash to UsabilityTest in Lib/test/test_decimal.py to test hashing on both C and Python implementations.
  • Added NEWS entry in Misc/NEWS.d/next/Library/.

@python-cla-bot

python-cla-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant