Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Lib/_pydecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4060,9 +4060,6 @@ def _regard_flags(self, *flags):
for flag in flags:
self._ignored_flags.remove(flag)

# We inherit object.__hash__, so we must deny this explicitly
__hash__ = None

def Etiny(self):
"""Returns Etiny (= Emin - prec + 1)"""
return int(self.Emin - self.prec + 1)
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3658,6 +3658,18 @@ def test_same_quantum(self):
self.assertRaises(TypeError, c.same_quantum, '1', 2)
self.assertRaises(TypeError, c.same_quantum, 1, '2')

def test_context_hash(self):
Context = self.decimal.Context
c1 = Context()
c2 = Context()
self.assertIsInstance(hash(c1), int)
self.assertIsInstance(hash(c2), int)
self.assertEqual(hash(c1), c1.__hash__())
self.assertNotEqual(hash(c1), hash(c2))
d = {c1: 'first', c2: 'second'}
self.assertEqual(d[c1], 'first')
self.assertEqual(d[c2], 'second')

def test_scaleb(self):
Decimal = self.decimal.Decimal
Context = self.decimal.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :class:`!_pydecimal.Context` hashable by inheriting :meth:`object.__hash__`, matching the behavior of :class:`!_decimal.Context` per :pep:`399`.
Loading