Skip to content

Commit

Permalink
Use ALWAYS_EQ instead of ANY
Browse files Browse the repository at this point in the history
  • Loading branch information
dg-pb committed Jan 7, 2025
1 parent 5e151aa commit 38ff471
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import contextlib
from inspect import Signature

from test.support import ALWAYS_EQ
from test.support import import_helper
from test.support import threading_helper

Expand Down Expand Up @@ -235,10 +236,10 @@ def test_placeholders(self):
self.assertEqual(actual_kwds, {})
# Checks via `is` and not `eq`
# thus unittest.mock.ANY isn't treated as Placeholder
p = self.partial(capture, unittest.mock.ANY)
p = self.partial(capture, ALWAYS_EQ)
actual_args, actual_kwds = p()
self.assertEqual(len(actual_args), 1)
self.assertIs(actual_args[0], unittest.mock.ANY)
self.assertIs(actual_args[0], ALWAYS_EQ)
self.assertEqual(actual_kwds, {})

def test_placeholders_optimization(self):
Expand All @@ -261,10 +262,11 @@ def test_placeholders_kw_restriction(self):
with self.assertRaisesRegex(TypeError, "Placeholder"):
self.partial(capture, a=PH)
# Passes, as checks via `is` and not `eq`
p = self.partial(capture, a=unittest.mock.ANY)
p = self.partial(capture, a=ALWAYS_EQ)
actual_args, actual_kwds = p()
self.assertEqual(actual_args, ())
self.assertEqual(actual_kwds, {'a': unittest.mock.ANY})
self.assertEqual(len(actual_kwds), 1)
self.assertIs(actual_kwds['a'], ALWAYS_EQ)

def test_construct_placeholder_singleton(self):
PH = self.module.Placeholder
Expand Down

0 comments on commit 38ff471

Please sign in to comment.