{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1992","repository_url":"https://api.github.com/repos/micropython/micropython","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1992/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1992/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1992/events","html_url":"https://github.com/micropython/micropython/issues/1992","id":149177894,"number":1992,"title":"unix: \"function does not take keyword arguments\" message can mislead","user":{"login":"peterhinch","id":8437477,"avatar_url":"https://avatars.githubusercontent.com/u/8437477?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhinch","html_url":"https://github.com/peterhinch","followers_url":"https://api.github.com/users/peterhinch/followers","following_url":"https://api.github.com/users/peterhinch/following{/other_user}","gists_url":"https://api.github.com/users/peterhinch/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhinch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhinch/subscriptions","organizations_url":"https://api.github.com/users/peterhinch/orgs","repos_url":"https://api.github.com/users/peterhinch/repos","events_url":"https://api.github.com/users/peterhinch/events{/privacy}","received_events_url":"https://api.github.com/users/peterhinch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-18T15:05:22Z","updated_at":"2016-04-19T17:28:01Z","closed_at":null,"body":"If function kw arguments are supplied from a dict, and the dict (erroneously) contains unexpected arguments, the above error message is rather misleading. \r\n```python\r\nd = {'argument' : 'A', 'bar' : 0}\r\n\r\ndef foo(*, bar=False):\r\n    print('foo')\r\nfoo(**d)\r\n```\r\nCpython produces the self-evident\r\n```\r\n>>> foo(**d)\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nTypeError: foo() got an unexpected keyword argument 'argument'\r\n>>> \r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/212027124","html_url":"https://github.com/micropython/micropython/issues/1992#issuecomment-212027124","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1992","id":212027124,"user":{"login":"peterhinch","id":8437477,"avatar_url":"https://avatars.githubusercontent.com/u/8437477?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhinch","html_url":"https://github.com/peterhinch","followers_url":"https://api.github.com/users/peterhinch/followers","following_url":"https://api.github.com/users/peterhinch/following{/other_user}","gists_url":"https://api.github.com/users/peterhinch/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhinch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhinch/subscriptions","organizations_url":"https://api.github.com/users/peterhinch/orgs","repos_url":"https://api.github.com/users/peterhinch/repos","events_url":"https://api.github.com/users/peterhinch/events{/privacy}","received_events_url":"https://api.github.com/users/peterhinch/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T17:28:01Z","updated_at":"2016-04-19T17:28:01Z","body":"I've encountered another manifestation of this. Its appearance depends on following the method of input exactly, with only the function def being entered in paste mode. It also requires the arg name to be long.\r\n```\r\n[adminpete@axolotl]: /mnt/qnap2/data/Projects/MicroPython/micropython/unix\r\n$ ./micropython\r\nMicroPython v1.7-64-gb122ed0-dirty on 2016-04-18; linux version\r\nUse Ctrl-D to exit, Ctrl-E for paste mode\r\n>>> bar = {'averylongnamehere': 11, 'g': 77}\r\n>>> \r\npaste mode; Ctrl-C to cancel, Ctrl-D to finish\r\n=== def foo(*,averylongnamehere = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7):\r\n===     print(averylongnamehere,b,c,d,e,f,g)\r\n=== \r\n=== \r\n>>> foo(b = 222, **bar)\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nTypeError: function does not take keyword arguments\r\n>>>\r\n```\r\nIn practise this error crops up periodically. As dictionary expansion is typically used for functions having many args locating the cause is tedious. I have found it necessary to use short names in real code. And it would be very helpful, where an unexpected argument is in the dict, for the error message to name the arg."}}