Title: bpo-44019: Implement operator.call(). by anntzer · Pull Request #27888 · python/cpython · GitHub
Open Graph Title: bpo-44019: Implement operator.call(). by anntzer · Pull Request #27888 · python/cpython
X Title: bpo-44019: Implement operator.call(). by anntzer · Pull Request #27888 · python/cpython
Description: Having operator.call(obj, arg) mean type(obj).__call__(obj, arg) is consistent with the other dunder operators. The semantics with *args, **kwargs then follow naturally from the single-arg semantics. I realize that I proposed different semantics in the original bug report, but that didn't even actually match to the proposed use case; the second proposal in the thread is the correct one. The semantics here work for at least two different use cases that I have seen: Using concurrent.futures.Executor.map on a list of callables (executor.map(operator.call, callables)). In that case the performance doesn't actually matter much and a Python helper would in fact be fine. Loading a "typed" csv file (cf. numpy.loadtxt), where each column has a separate type, e.g. converters = [int, float, int, float] lines = [ # Assume that we already `str.split` them. ["1", "2.2", "3", "4.4"], ["5", "6.6", "7", "8.8"], ] [[*map(operator.call, converters, words)] for words in lines] # faster than the list comprehension [[conv(word) for conv, word in zip(converters, words)] for words in lines] Here the performance actually matters (with numpy, one may easily be loading millions of rows). A simple benchmark gives $ ./python -mtimeit -s 'from operator import call; funcs = [int, float, float, int]; inputs = ["1", "2", "3", "4"]' -- '[*map(call, funcs, inputs)]' 500000 loops, best of 5: 761 nsec per loop $ ./python -mtimeit -s 'from operator import call; funcs = [int, float, float, int]; inputs = ["1", "2", "3", "4"]' -- '[func(inp) for func, inp in zip(funcs, inputs)]' 200000 loops, best of 5: 1.07 usec per loop i.e. map(operator.call, ...) gives a significant speedup. https://bugs.python.org/issue44019
Open Graph Description: Having operator.call(obj, arg) mean type(obj).__call__(obj, arg) is consistent with the other dunder operators. The semantics with *args, **kwargs then follow naturally from the single-arg semanti...
X Description: Having operator.call(obj, arg) mean type(obj).__call__(obj, arg) is consistent with the other dunder operators. The semantics with *args, **kwargs then follow naturally from the single-arg semanti...
Opengraph URL: https://github.com/python/cpython/pull/27888
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:8f64fa34-8d6d-2e4e-cd8e-d132d6693bce |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B92A:20CC71:1C97597:26005C3:6A5D5052 |
| html-safe-nonce | bc1c6681f68411855033cf92802eba8197deaf3e4f3c37e38543bc081e85561b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTJBOjIwQ0M3MToxQzk3NTk3OjI2MDA1QzM6NkE1RDUwNTIiLCJ2aXNpdG9yX2lkIjoiMjAxNDQ0NTI4MTE0OTI3NjI0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 20f1123b33f19471f9de05cc72a4914031aa415bc0889c71565476a0c1a6a981 |
| hovercard-subject-tag | pull_request:717303451 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/27888/files |
| twitter:image | https://avatars.githubusercontent.com/u/1322974?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1322974?s=400&v=4 |
| og:image:alt | Having operator.call(obj, arg) mean type(obj).__call__(obj, arg) is consistent with the other dunder operators. The semantics with *args, **kwargs then follow naturally from the single-arg semanti... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width