Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-119127: functools.partial placeholders#119827
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
ee7333c8bcc462c67c9b4680d9009591ff5067e9388af20b3607a0b1f55801e58941453722e07a79c2af12aaa7292c767b496a9d238d9c11707b95714b38ca32bca198576493a3fd2d608529936fea348caec6e8115b8c53f5f00b202c9292c16d38400ff558ccc38fe7c82c7c9b7ef3e59d7117bfc5917957a978aaee6afe8e0ad00dd80ed352cfa9038ed549b8c71bc1fdbd30672211185510266b4fadd58a125971fbb9033650d31e5d1a3d39b09e4c5df16f12f882dd600f9cb653d255524404044e800217b38ee45011f47db3c872bdfd16189a6c6ef21c8d73ea8bd3ae70e47ed2eacf5ef78d8d30a8640e6e3d28266c305d14bf68cee642d58d6c28e8744bcbb8964704881ae6c3ad7d95e5d484File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1933,7 +1933,10 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): | ||
| # If positional-only parameter is bound by partial, | ||
| # it effectively disappears from the signature | ||
| # However, if it is a Placeholder it is not removed | ||
| # And also looses default value | ||
| if arg_value is functools.Placeholder: | ||
| new_params[param_name] = param.replace(default=_empty) | ||
| else: | ||
| new_params.pop(param_name) | ||
| continue | ||
| @@ -1957,9 +1960,13 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): | ||
| else: | ||
| # was passed as a positional argument | ||
| # Do not pop if it is a Placeholder | ||
| # also change kind to positional only | ||
| # and remove default | ||
| if arg_value is functools.Placeholder: | ||
dg-pb marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| new_param = param.replace( | ||
| kind=_POSITIONAL_ONLY, | ||
| default=_empty | ||
| ) | ||
| new_params[param_name] = new_param | ||
| else: | ||
| new_params.pop(param_name) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -242,6 +242,12 @@ def test_placeholders_optimization(self): | ||
| got, empty = p3(5) | ||
| expected = (-1, 0, 1, 2, 3, 4, 5) | ||
| self.assertTrue(expected == got and empty == {}) | ||
| # inner partial has placeholders and outer partial has no args case | ||
| p = self.partial(capture, PH, 0) | ||
| p2 = self.partial(p) | ||
| expected = (PH, 0) | ||
| self.assertTrue(expected == p2.args) | ||
| self.assertTrue(((1, 0), {}) == p2(1)) | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| def test_construct_placeholder_singleton(self): | ||
| PH = self.module.Placeholder | ||
| @@ -550,7 +556,7 @@ class TestPartialPySubclass(TestPartialPy): | ||
| def test_subclass_optimization(self): | ||
| p = py_functools.partial(min, 2) | ||
dg-pb marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| p2 = self.partial(p, 1) | ||
| assert p2.funcis min | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| assert p2(0) == 0 | ||
| @@ -696,7 +702,7 @@ class PartialMethodSubclass(functools.partialmethod): | ||
| pass | ||
| p = functools.partialmethod(min, 2) | ||
| p2 = PartialMethodSubclass(p, 1) | ||
| assert p2.funcis min | ||
| assert p2.__get__(0)() == 0 | ||