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 |
|---|---|---|
| @@ -300,9 +300,11 @@ def __reduce__(self): | ||
| Placeholder = _PlaceholderType() | ||
| def _partial_prepare_merger(args): | ||
| nargs = len(args) | ||
| if not nargs: | ||
| return 0, None | ||
| order = list() | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| i, j = 0, nargs | ||
| for a in args: | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if a is Placeholder: | ||
| order.append(j) | ||
| @@ -311,45 +313,35 @@ def _partial_prepare_merger(args): | ||
| order.append(i) | ||
| i += 1 | ||
| phcount = j - nargs | ||
| merger = itemgetter(*order) if phcount else None | ||
| return phcount, merger | ||
| def _partial_prepare_new(cls, func, args, keywords): | ||
| if args and args[-1] is Placeholder: | ||
| raise TypeError("trailing Placeholders are not allowed") | ||
dg-pb marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if isinstance(func, cls): | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| pto_phcount = func._phcount | ||
| tot_args = func.args | ||
| if args: | ||
| tot_args += args | ||
| if pto_phcount: | ||
| # merge args with args of `func` which is `partial` | ||
| nargs = len(args) | ||
| if nargs < pto_phcount: | ||
| tot_args += (Placeholder,) * (pto_phcount - nargs) | ||
| tot_args = func._merger(tot_args) | ||
| if nargs > pto_phcount: | ||
| tot_args += args[pto_phcount:] | ||
| phcount, merger = _partial_prepare_merger(tot_args) | ||
| elif pto_phcount: # not args | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| phcount, merger =pto_phcount, func._merger | ||
| else: # notargs and not pto_phcount | ||
| phcount, merger = 0, None | ||
| keywords = {**func.keywords, **keywords} | ||
| func = func.func | ||
| else: | ||
| tot_args = args | ||
| phcount, merger = _partial_prepare_merger(tot_args) | ||
| return func, tot_args, keywords, phcount, merger | ||
| def _partial_repr(self): | ||
| @@ -415,12 +407,9 @@ def __setstate__(self, state): | ||
| (namespace is not None and not isinstance(namespace, dict))): | ||
| raise TypeError("invalid partial state") | ||
| if args and args[-1] is Placeholder: | ||
| raise TypeError("trailing Placeholders are not allowed") | ||
| phcount, merger = _partial_prepare_merger(args) | ||
| args = tuple(args) # just in case it's a subclass | ||
| if kwds is None: | ||