{"action":"created","comment":{"url":"https://api.github.com/repos/pybind/pybind11/pulls/comments/77491917","id":77491917,"diff_hunk":"@@ -1589,24 +1589,56 @@ It is also possible to call python functions via ``operator()``.\n     py::object result_py = f(1234, \"hello\", some_instance);","path":"docs/advanced.rst","position":1,"original_position":1,"commit_id":"1f13b0c69e27b520b319fdcc170e0e52fb957644","original_commit_id":"1f13b0c69e27b520b319fdcc170e0e52fb957644","user":{"login":"aldanor","id":2418513,"avatar_url":"https://avatars.githubusercontent.com/u/2418513?v=3","gravatar_id":"","url":"https://api.github.com/users/aldanor","html_url":"https://github.com/aldanor","followers_url":"https://api.github.com/users/aldanor/followers","following_url":"https://api.github.com/users/aldanor/following{/other_user}","gists_url":"https://api.github.com/users/aldanor/gists{/gist_id}","starred_url":"https://api.github.com/users/aldanor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldanor/subscriptions","organizations_url":"https://api.github.com/users/aldanor/orgs","repos_url":"https://api.github.com/users/aldanor/repos","events_url":"https://api.github.com/users/aldanor/events{/privacy}","received_events_url":"https://api.github.com/users/aldanor/received_events","type":"User","site_admin":false},"body":"Yea, agreed, most of this library now falls under \"Advanced\", and things like objects in pytypes.h are scarcely mentioned.\r\n\r\nSplitting into sections could be good -- eg wrapper types (dict, tuple etc), handle/object, utility (print), eigen, NumPy (I'd be willing to rewrite the docs on this one).","created_at":"2016-09-05T09:14:39Z","updated_at":"2016-09-05T09:14:39Z","html_url":"https://github.com/pybind/pybind11/pull/372#discussion_r77491917","pull_request_url":"https://api.github.com/repos/pybind/pybind11/pulls/372","_links":{"self":{"href":"https://api.github.com/repos/pybind/pybind11/pulls/comments/77491917"},"html":{"href":"https://github.com/pybind/pybind11/pull/372#discussion_r77491917"},"pull_request":{"href":"https://api.github.com/repos/pybind/pybind11/pulls/372"}}},"pull_request":{"url":"https://api.github.com/repos/pybind/pybind11/pulls/372","id":83179676,"html_url":"https://github.com/pybind/pybind11/pull/372","diff_url":"https://github.com/pybind/pybind11/pull/372.diff","patch_url":"https://github.com/pybind/pybind11/pull/372.patch","issue_url":"https://api.github.com/repos/pybind/pybind11/issues/372","number":372,"state":"open","locked":false,"title":"Keyword arguments and generalized unpacking for C++ API","user":{"login":"dean0x7d","id":4831417,"avatar_url":"https://avatars.githubusercontent.com/u/4831417?v=3","gravatar_id":"","url":"https://api.github.com/users/dean0x7d","html_url":"https://github.com/dean0x7d","followers_url":"https://api.github.com/users/dean0x7d/followers","following_url":"https://api.github.com/users/dean0x7d/following{/other_user}","gists_url":"https://api.github.com/users/dean0x7d/gists{/gist_id}","starred_url":"https://api.github.com/users/dean0x7d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dean0x7d/subscriptions","organizations_url":"https://api.github.com/users/dean0x7d/orgs","repos_url":"https://api.github.com/users/dean0x7d/repos","events_url":"https://api.github.com/users/dean0x7d/events{/privacy}","received_events_url":"https://api.github.com/users/dean0x7d/received_events","type":"User","site_admin":false},"body":"### General idea\r\n\r\nA Python function can be called with the syntax:\r\n```python\r\nfoo(a1, a2, *args, ka=1, kb=2, **kwargs)\r\n```\r\nThis PR adds support for the equivalent syntax in C++:\r\n```c++\r\nfoo(a1, a2, *args, \"ka\"_a=1, \"kb\"_a=2, **kwargs)\r\n```\r\n\r\nIn addition, generalized unpacking is implemented, as per [PEP 448](https://www.python.org/dev/peps/pep-0448/), which allows calls with multiple * and ** unpackings in Python:\r\n```python\r\nbar(*args1, 99, *args2, 101, **kwargs1, kz=200, **kwargs2)\r\n```\r\nand in C++:\r\n```c++\r\nbar(*args1, 99, *args2, 101, **kwargs1, \"kz\"_a=200, **kwargs2)\r\n```\r\n\r\n### Impact on compile time\r\n\r\nThe new functionality is SFINAEd-off into a separate instantiation path from the existing positional-only arguments. Thus, the compile time will not increase for existing code. When (and only when) keywords and/or generalized unpacking are used, a little more template metaprogramming is in play, but it's not really any more complicated than the existing `def`/`arg` machinery for naming arguments and assigning default values. There are no compile time slowdowns as far as I've seen.\r\n\r\n### Python version compatibility\r\n\r\nPEP 448 is implemented only in Python >= 3.5, but the C++ API allows these kinds of calls for any Python version. Limiting it by version is also possible, but I don't think it's necessary. The function calls are still perfectly valid, it's just that:\r\n```python\r\nf(**kwargs1, **kwargs2)  # Python 3.5\r\n```\r\nwould look like:\r\n```python\r\nkwargs1.update(kwargs2)  # Python < 3.5\r\nf(**kwargs1)\r\n```\r\n\r\n### Applications\r\n\r\nThis PR also implements a few functions using this new functionality.\r\n\r\nPython's `print` function is replicated in the C++ API including the keyword arguments `sep`, `end`, `file`, `flush`. E.g.:\r\n```c++\r\npy::print(v1, v2, \"sep\"_a=\" -- \");\r\n```\r\n\r\nThe `str.format` method is added. Together with the `_s` UDL for `str`, this allows the following syntax in C++:\r\n```c++\r\nauto str1 = \"Hello, {}! Your number is {}\"_s.format(\"World\", 42);\r\n// or\r\nauto str2 = \"Hello, {name}! Your number is {number}\"_s.format(\"number\"_a=42, \"name\"_a=\"World\");\r\n```\r\n\r\nThe `py::dict` class also gets a keyword constructor which replicates its Python counterpart:\r\n```c++\r\nauto d = dict(\"number\"_a=42, \"name\"_a=\"World\");\r\n```\r\n\r\n### Feedback?\r\n\r\nI hope this is not considered too much of an abuse of C++. Let me know if this is OK so far.","created_at":"2016-08-29T22:34:31Z","updated_at":"2016-09-05T09:14:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"06c81aee9baeb08229f68c5c05c5f2cc0a940748","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pybind/pybind11/pulls/372/commits","review_comments_url":"https://api.github.com/repos/pybind/pybind11/pulls/372/comments","review_comment_url":"https://api.github.com/repos/pybind/pybind11/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pybind/pybind11/issues/372/comments","statuses_url":"https://api.github.com/repos/pybind/pybind11/statuses/1f13b0c69e27b520b319fdcc170e0e52fb957644","head":{"label":"dean0x7d:keywords","ref":"keywords","sha":"1f13b0c69e27b520b319fdcc170e0e52fb957644","user":{"login":"dean0x7d","id":4831417,"avatar_url":"https://avatars.githubusercontent.com/u/4831417?v=3","gravatar_id":"","url":"https://api.github.com/users/dean0x7d","html_url":"https://github.com/dean0x7d","followers_url":"https://api.github.com/users/dean0x7d/followers","following_url":"https://api.github.com/users/dean0x7d/following{/other_user}","gists_url":"https://api.github.com/users/dean0x7d/gists{/gist_id}","starred_url":"https://api.github.com/users/dean0x7d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dean0x7d/subscriptions","organizations_url":"https://api.github.com/users/dean0x7d/orgs","repos_url":"https://api.github.com/users/dean0x7d/repos","events_url":"https://api.github.com/users/dean0x7d/events{/privacy}","received_events_url":"https://api.github.com/users/dean0x7d/received_events","type":"User","site_admin":false},"repo":{"id":59426490,"name":"pybind11","full_name":"dean0x7d/pybind11","owner":{"login":"dean0x7d","id":4831417,"avatar_url":"https://avatars.githubusercontent.com/u/4831417?v=3","gravatar_id":"","url":"https://api.github.com/users/dean0x7d","html_url":"https://github.com/dean0x7d","followers_url":"https://api.github.com/users/dean0x7d/followers","following_url":"https://api.github.com/users/dean0x7d/following{/other_user}","gists_url":"https://api.github.com/users/dean0x7d/gists{/gist_id}","starred_url":"https://api.github.com/users/dean0x7d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dean0x7d/subscriptions","organizations_url":"https://api.github.com/users/dean0x7d/orgs","repos_url":"https://api.github.com/users/dean0x7d/repos","events_url":"https://api.github.com/users/dean0x7d/events{/privacy}","received_events_url":"https://api.github.com/users/dean0x7d/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dean0x7d/pybind11","description":"Seamless operability between C++11 and Python","fork":true,"url":"https://api.github.com/repos/dean0x7d/pybind11","forks_url":"https://api.github.com/repos/dean0x7d/pybind11/forks","keys_url":"https://api.github.com/repos/dean0x7d/pybind11/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dean0x7d/pybind11/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dean0x7d/pybind11/teams","hooks_url":"https://api.github.com/repos/dean0x7d/pybind11/hooks","issue_events_url":"https://api.github.com/repos/dean0x7d/pybind11/issues/events{/number}","events_url":"https://api.github.com/repos/dean0x7d/pybind11/events","assignees_url":"https://api.github.com/repos/dean0x7d/pybind11/assignees{/user}","branches_url":"https://api.github.com/repos/dean0x7d/pybind11/branches{/branch}","tags_url":"https://api.github.com/repos/dean0x7d/pybind11/tags","blobs_url":"https://api.github.com/repos/dean0x7d/pybind11/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dean0x7d/pybind11/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dean0x7d/pybind11/git/refs{/sha}","trees_url":"https://api.github.com/repos/dean0x7d/pybind11/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dean0x7d/pybind11/statuses/{sha}","languages_url":"https://api.github.com/repos/dean0x7d/pybind11/languages","stargazers_url":"https://api.github.com/repos/dean0x7d/pybind11/stargazers","contributors_url":"https://api.github.com/repos/dean0x7d/pybind11/contributors","subscribers_url":"https://api.github.com/repos/dean0x7d/pybind11/subscribers","subscription_url":"https://api.github.com/repos/dean0x7d/pybind11/subscription","commits_url":"https://api.github.com/repos/dean0x7d/pybind11/commits{/sha}","git_commits_url":"https://api.github.com/repos/dean0x7d/pybind11/git/commits{/sha}","comments_url":"https://api.github.com/repos/dean0x7d/pybind11/comments{/number}","issue_comment_url":"https://api.github.com/repos/dean0x7d/pybind11/issues/comments{/number}","contents_url":"https://api.github.com/repos/dean0x7d/pybind11/contents/{+path}","compare_url":"https://api.github.com/repos/dean0x7d/pybind11/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dean0x7d/pybind11/merges","archive_url":"https://api.github.com/repos/dean0x7d/pybind11/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dean0x7d/pybind11/downloads","issues_url":"https://api.github.com/repos/dean0x7d/pybind11/issues{/number}","pulls_url":"https://api.github.com/repos/dean0x7d/pybind11/pulls{/number}","milestones_url":"https://api.github.com/repos/dean0x7d/pybind11/milestones{/number}","notifications_url":"https://api.github.com/repos/dean0x7d/pybind11/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dean0x7d/pybind11/labels{/name}","releases_url":"https://api.github.com/repos/dean0x7d/pybind11/releases{/id}","deployments_url":"https://api.github.com/repos/dean0x7d/pybind11/deployments","created_at":"2016-05-22T17:59:20Z","updated_at":"2016-05-22T17:59:21Z","pushed_at":"2016-09-04T23:16:03Z","git_url":"git://github.com/dean0x7d/pybind11.git","ssh_url":"git@github.com:dean0x7d/pybind11.git","clone_url":"https://github.com/dean0x7d/pybind11.git","svn_url":"https://github.com/dean0x7d/pybind11","homepage":null,"size":1494,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pybind:master","ref":"master","sha":"f3be07c6613c8463a2faea12806dcd1bd788caf9","user":{"login":"pybind","id":17565521,"avatar_url":"https://avatars.githubusercontent.com/u/17565521?v=3","gravatar_id":"","url":"https://api.github.com/users/pybind","html_url":"https://github.com/pybind","followers_url":"https://api.github.com/users/pybind/followers","following_url":"https://api.github.com/users/pybind/following{/other_user}","gists_url":"https://api.github.com/users/pybind/gists{/gist_id}","starred_url":"https://api.github.com/users/pybind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pybind/subscriptions","organizations_url":"https://api.github.com/users/pybind/orgs","repos_url":"https://api.github.com/users/pybind/repos","events_url":"https://api.github.com/users/pybind/events{/privacy}","received_events_url":"https://api.github.com/users/pybind/received_events","type":"Organization","site_admin":false},"repo":{"id":38581626,"name":"pybind11","full_name":"pybind/pybind11","owner":{"login":"pybind","id":17565521,"avatar_url":"https://avatars.githubusercontent.com/u/17565521?v=3","gravatar_id":"","url":"https://api.github.com/users/pybind","html_url":"https://github.com/pybind","followers_url":"https://api.github.com/users/pybind/followers","following_url":"https://api.github.com/users/pybind/following{/other_user}","gists_url":"https://api.github.com/users/pybind/gists{/gist_id}","starred_url":"https://api.github.com/users/pybind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pybind/subscriptions","organizations_url":"https://api.github.com/users/pybind/orgs","repos_url":"https://api.github.com/users/pybind/repos","events_url":"https://api.github.com/users/pybind/events{/privacy}","received_events_url":"https://api.github.com/users/pybind/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pybind/pybind11","description":"Seamless operability between C++11 and Python","fork":false,"url":"https://api.github.com/repos/pybind/pybind11","forks_url":"https://api.github.com/repos/pybind/pybind11/forks","keys_url":"https://api.github.com/repos/pybind/pybind11/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pybind/pybind11/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pybind/pybind11/teams","hooks_url":"https://api.github.com/repos/pybind/pybind11/hooks","issue_events_url":"https://api.github.com/repos/pybind/pybind11/issues/events{/number}","events_url":"https://api.github.com/repos/pybind/pybind11/events","assignees_url":"https://api.github.com/repos/pybind/pybind11/assignees{/user}","branches_url":"https://api.github.com/repos/pybind/pybind11/branches{/branch}","tags_url":"https://api.github.com/repos/pybind/pybind11/tags","blobs_url":"https://api.github.com/repos/pybind/pybind11/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pybind/pybind11/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pybind/pybind11/git/refs{/sha}","trees_url":"https://api.github.com/repos/pybind/pybind11/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pybind/pybind11/statuses/{sha}","languages_url":"https://api.github.com/repos/pybind/pybind11/languages","stargazers_url":"https://api.github.com/repos/pybind/pybind11/stargazers","contributors_url":"https://api.github.com/repos/pybind/pybind11/contributors","subscribers_url":"https://api.github.com/repos/pybind/pybind11/subscribers","subscription_url":"https://api.github.com/repos/pybind/pybind11/subscription","commits_url":"https://api.github.com/repos/pybind/pybind11/commits{/sha}","git_commits_url":"https://api.github.com/repos/pybind/pybind11/git/commits{/sha}","comments_url":"https://api.github.com/repos/pybind/pybind11/comments{/number}","issue_comment_url":"https://api.github.com/repos/pybind/pybind11/issues/comments{/number}","contents_url":"https://api.github.com/repos/pybind/pybind11/contents/{+path}","compare_url":"https://api.github.com/repos/pybind/pybind11/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pybind/pybind11/merges","archive_url":"https://api.github.com/repos/pybind/pybind11/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pybind/pybind11/downloads","issues_url":"https://api.github.com/repos/pybind/pybind11/issues{/number}","pulls_url":"https://api.github.com/repos/pybind/pybind11/pulls{/number}","milestones_url":"https://api.github.com/repos/pybind/pybind11/milestones{/number}","notifications_url":"https://api.github.com/repos/pybind/pybind11/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pybind/pybind11/labels{/name}","releases_url":"https://api.github.com/repos/pybind/pybind11/releases{/id}","deployments_url":"https://api.github.com/repos/pybind/pybind11/deployments","created_at":"2015-07-05T19:46:48Z","updated_at":"2016-09-04T11:11:26Z","pushed_at":"2016-09-05T08:21:34Z","git_url":"git://github.com/pybind/pybind11.git","ssh_url":"git@github.com:pybind/pybind11.git","clone_url":"https://github.com/pybind/pybind11.git","svn_url":"https://github.com/pybind/pybind11","homepage":null,"size":2149,"stargazers_count":1460,"watchers_count":1460,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":151,"mirror_url":null,"open_issues_count":16,"forks":151,"open_issues":16,"watchers":1460,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pybind/pybind11/pulls/372"},"html":{"href":"https://github.com/pybind/pybind11/pull/372"},"issue":{"href":"https://api.github.com/repos/pybind/pybind11/issues/372"},"comments":{"href":"https://api.github.com/repos/pybind/pybind11/issues/372/comments"},"review_comments":{"href":"https://api.github.com/repos/pybind/pybind11/pulls/372/comments"},"review_comment":{"href":"https://api.github.com/repos/pybind/pybind11/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pybind/pybind11/pulls/372/commits"},"statuses":{"href":"https://api.github.com/repos/pybind/pybind11/statuses/1f13b0c69e27b520b319fdcc170e0e52fb957644"}}}}
{"actor":{"display_login":"aldanor"}}