pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/103404.patch

format(arg=', '.join( - param.name for param in pos_only_param_in_kwargs))) + raise TypeError( + 'got some positional-only arguments passed as ' + 'keyword arguments: {arg!r} '.format( + arg=', '.join( + param.name + for param in pos_only_param_in_kwargs + ), + ), + ) raise TypeError( 'got an unexpected keyword argument {arg!r}'.format( arg=next(iter(kwargs)))) From 366bb96d7617d8fa9bd8566d206b7af022ad98cf Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 5 May 2024 09:49:44 -0400 Subject: [PATCH 05/13] Simplify test case --- Lib/test/test_inspect/test_inspect.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index d455251f2261120..d3a755e816741f8 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5081,11 +5081,11 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs): with self.assertRaisesRegex(TypeError, "missing 2 required positional arguments"): self.call(test, a_po=1, b_po=2) - def without_var_kwargs(a_po, b_po, c_po=3, /, foo=42, *, bar=50): - return a_po, b_po, c_po, foo, bar + def without_var_kwargs(c_po=3, /): + return c_po with self.assertRaisesRegex(TypeError, "positional-only arguments passed as keyword"): - self.call(without_var_kwargs, 1, 2, foo=4, bar=5, c_po=10) + self.call(without_var_kwargs, c_po=10) def test_signature_bind_with_self_arg(self): # Issue #17071: one of the parameters is named "self From 2f792eb04bd600e731d034fab513cd45b0470767 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 5 May 2024 09:53:25 -0400 Subject: [PATCH 06/13] Add test cases --- Lib/test/test_inspect/test_inspect.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index d3a755e816741f8..cb572aebf3e7a1e 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5075,6 +5075,12 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs): self.assertEqual(self.call(test, 1, 2, foo=4, bar=5, c_po=10), (1, 2, 3, 4, 5, {'c_po': 10})) + self.assertEqual(self.call(test, 1, 2, 3, c_po=10, foo=4, bar=5), + (1, 2, 3, 4, 5, {'c_po': 10})) + + self.assertEqual(self.call(test, 1, 2, 3, foo=4, bar=5, c_po=10), + (1, 2, 3, 4, 5, {'c_po': 10})) + self.assertEqual(self.call(test, 1, 2, c_po=4), (1, 2, 3, 42, 50, {'c_po': 4})) From 5951ad901e2dbb456cadf0c863b3f29ba78eae7e Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 5 May 2024 10:05:02 -0400 Subject: [PATCH 07/13] Use elif --- Lib/inspect.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 94d30263cff0a88..28837ec701976a4 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -3295,20 +3295,21 @@ def _bind(self, args, kwargs, *, partial=False): if kwargs_param is not None: # Process our '**kwargs'-like parameter arguments[kwargs_param.name] = kwargs - else: - if pos_only_param_in_kwargs: - raise TypeError( - 'got some positional-only arguments passed as ' - 'keyword arguments: {arg!r} '.format( - arg=', '.join( - param.name - for param in pos_only_param_in_kwargs - ), + elif pos_only_param_in_kwargs: + raise TypeError( + 'got some positional-only arguments passed as ' + 'keyword arguments: {arg!r} '.format( + arg=', '.join( + param.name + for param in pos_only_param_in_kwargs ), - ) + ), + ) + else: raise TypeError( 'got an unexpected keyword argument {arg!r}'.format( - arg=next(iter(kwargs)))) + arg=next(iter(kwargs))) + ) return self._bound_arguments_cls(self, arguments) From 2ecde833fe273703ff40573491099f5cb544626d Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 5 May 2024 10:31:22 -0400 Subject: [PATCH 08/13] Refactor to avoid pop-and-maybe-put-back pattern --- Lib/inspect.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 28837ec701976a4..5d41839054aca68 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -3271,6 +3271,9 @@ def _bind(self, args, kwargs, *, partial=False): # before reaching the last parameter before *args. continue + if param.kind == _POSITIONAL_ONLY: + continue + param_name = param.name try: arg_val = kwargs.pop(param_name) @@ -3283,13 +3286,8 @@ def _bind(self, args, kwargs, *, partial=False): param.default is _empty): raise TypeError('missing a required argument: {arg!r}'. \ format(arg=param_name)) from None - else: - if param.kind == _POSITIONAL_ONLY: - # Restore the param in case there is a kwargs_param - kwargs[param_name] = arg_val - else: - arguments[param_name] = arg_val + arguments[param_name] = arg_val if kwargs: if kwargs_param is not None: From db2d92595310b115bc98dedc7f14c502e114b2ea Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 5 May 2024 10:32:40 -0400 Subject: [PATCH 09/13] Remove unnecessary cosmetic changes --- Lib/inspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 5d41839054aca68..fe64949e4fe80fa 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -3286,6 +3286,7 @@ def _bind(self, args, kwargs, *, partial=False): param.default is _empty): raise TypeError('missing a required argument: {arg!r}'. \ format(arg=param_name)) from None + else: arguments[param_name] = arg_val @@ -3306,8 +3307,7 @@ def _bind(self, args, kwargs, *, partial=False): else: raise TypeError( 'got an unexpected keyword argument {arg!r}'.format( - arg=next(iter(kwargs))) - ) + arg=next(iter(kwargs)))) return self._bound_arguments_cls(self, arguments) From 69162908a945b998b62a39af9089c6feb8e6b4ff Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 5 May 2024 10:57:58 -0400 Subject: [PATCH 10/13] Test multiple pos-only args passed by keyword --- Lib/inspect.py | 3 ++- Lib/test/test_inspect/test_inspect.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index fe64949e4fe80fa..46fa0b45eb9a359 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -3204,6 +3204,7 @@ def _bind(self, args, kwargs, *, partial=False): # Raise a TypeError once we are sure there is no # **kwargs param later. pos_only_param_in_kwargs.append(param) + continue parameters_ex = (param,) break elif (param.kind == _VAR_KEYWORD or @@ -3297,7 +3298,7 @@ def _bind(self, args, kwargs, *, partial=False): elif pos_only_param_in_kwargs: raise TypeError( 'got some positional-only arguments passed as ' - 'keyword arguments: {arg!r} '.format( + 'keyword arguments: {arg!r}'.format( arg=', '.join( param.name for param in pos_only_param_in_kwargs diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index cb572aebf3e7a1e..f53069edf164cb6 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5087,11 +5087,14 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs): with self.assertRaisesRegex(TypeError, "missing 2 required positional arguments"): self.call(test, a_po=1, b_po=2) - def without_var_kwargs(c_po=3, /): - return c_po + def without_var_kwargs(c_po=3, d_po=4, /): + return c_po, d_po - with self.assertRaisesRegex(TypeError, "positional-only arguments passed as keyword"): - self.call(without_var_kwargs, c_po=10) + with self.assertRaisesRegex( + TypeError, + "positional-only arguments passed as keyword arguments: 'c_po, d_po'", + ): + self.call(without_var_kwargs, c_po=33, d_po=44) def test_signature_bind_with_self_arg(self): # Issue #17071: one of the parameters is named "self From 1ec398b70028723d0b47b5f6cf958c5f11cc9c65 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 10 May 2024 08:27:24 -0400 Subject: [PATCH 11/13] Remove superfluous continue --- Lib/inspect.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 46fa0b45eb9a359..9c983e861b101d8 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -3272,9 +3272,6 @@ def _bind(self, args, kwargs, *, partial=False): # before reaching the last parameter before *args. continue - if param.kind == _POSITIONAL_ONLY: - continue - param_name = param.name try: arg_val = kwargs.pop(param_name) From f1565de5658f3beeef5784966055c780291b231c Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 10 May 2024 08:29:18 -0400 Subject: [PATCH 12/13] [tests] Use distinct value for c_po kwarg --- Lib/test/test_inspect/test_inspect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index f53069edf164cb6..097a3e837384ada 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5075,11 +5075,11 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs): self.assertEqual(self.call(test, 1, 2, foo=4, bar=5, c_po=10), (1, 2, 3, 4, 5, {'c_po': 10})) - self.assertEqual(self.call(test, 1, 2, 3, c_po=10, foo=4, bar=5), - (1, 2, 3, 4, 5, {'c_po': 10})) + self.assertEqual(self.call(test, 1, 2, 3, c_po=30, foo=4, bar=5), + (1, 2, 3, 4, 5, {'c_po': 30})) - self.assertEqual(self.call(test, 1, 2, 3, foo=4, bar=5, c_po=10), - (1, 2, 3, 4, 5, {'c_po': 10})) + self.assertEqual(self.call(test, 1, 2, 3, foo=4, bar=5, c_po=30), + (1, 2, 3, 4, 5, {'c_po': 30})) self.assertEqual(self.call(test, 1, 2, c_po=4), (1, 2, 3, 42, 50, {'c_po': 4})) From 52facb0a9d96125ddd5b0f0d67912a6a8fe84ba5 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 12 May 2024 09:40:30 -0400 Subject: [PATCH 13/13] fixup! [tests] Use distinct value for c_po kwarg --- Lib/test/test_inspect/test_inspect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 097a3e837384ada..5aa3de45d70a080 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5075,11 +5075,11 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs): self.assertEqual(self.call(test, 1, 2, foo=4, bar=5, c_po=10), (1, 2, 3, 4, 5, {'c_po': 10})) - self.assertEqual(self.call(test, 1, 2, 3, c_po=30, foo=4, bar=5), - (1, 2, 3, 4, 5, {'c_po': 30})) + self.assertEqual(self.call(test, 1, 2, 30, c_po=31, foo=4, bar=5), + (1, 2, 30, 4, 5, {'c_po': 31})) - self.assertEqual(self.call(test, 1, 2, 3, foo=4, bar=5, c_po=30), - (1, 2, 3, 4, 5, {'c_po': 30})) + self.assertEqual(self.call(test, 1, 2, 30, foo=4, bar=5, c_po=31), + (1, 2, 30, 4, 5, {'c_po': 31})) self.assertEqual(self.call(test, 1, 2, c_po=4), (1, 2, 3, 42, 50, {'c_po': 4})) pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

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