2121import contextlib
2222from inspect import Signature
2323
24+ from test .support import ALWAYS_EQ
2425from test .support import import_helper
2526from test .support import threading_helper
2627from test .support import cpython_only
@@ -244,6 +245,13 @@ def test_placeholders(self):
244245 actual_args , actual_kwds = p ('x' , 'y' )
245246 self .assertEqual (actual_args , ('x' , 0 , 'y' , 1 ))
246247 self .assertEqual (actual_kwds , {})
248+ # Checks via `is` and not `eq`
249+ # thus ALWAYS_EQ isn't treated as Placeholder
250+ p = self .partial (capture , ALWAYS_EQ )
251+ actual_args , actual_kwds = p ()
252+ self .assertEqual (len (actual_args ), 1 )
253+ self .assertIs (actual_args [0 ], ALWAYS_EQ )
254+ self .assertEqual (actual_kwds , {})
247255
248256 def test_placeholders_optimization (self ):
249257 PH = self .module .Placeholder
@@ -260,6 +268,17 @@ def test_placeholders_optimization(self):
260268 self .assertEqual (p2 .args , (PH , 0 ))
261269 self .assertEqual (p2 (1 ), ((1 , 0 ), {}))
262270
271+ def test_placeholders_kw_restriction (self ):
272+ PH = self .module .Placeholder
273+ with self .assertRaisesRegex (TypeError , "Placeholder" ):
274+ self .partial (capture , a = PH )
275+ # Passes, as checks via `is` and not `eq`
276+ p = self .partial (capture , a = ALWAYS_EQ )
277+ actual_args , actual_kwds = p ()
278+ self .assertEqual (actual_args , ())
279+ self .assertEqual (len (actual_kwds ), 1 )
280+ self .assertIs (actual_kwds ['a' ], ALWAYS_EQ )
281+
263282 def test_construct_placeholder_singleton (self ):
264283 PH = self .module .Placeholder
265284 tp = type (PH )
0 commit comments