Skip to content

gh-125028: Prohibit placeholders in partial keywords #126062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Prev Previous commit
Next Next commit
Use ALWAYS_EQ instead of ANY
  • Loading branch information
dg-pb committed Jan 7, 2025
commit 38ff4718d094c035cbbfaefd3329604958e2931c
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
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy