{"action":"created","issue":{"url":"https://api.github.com/repos/skulpt/skulpt/issues/97","labels_url":"https://api.github.com/repos/skulpt/skulpt/issues/97/labels{/name}","comments_url":"https://api.github.com/repos/skulpt/skulpt/issues/97/comments","events_url":"https://api.github.com/repos/skulpt/skulpt/issues/97/events","html_url":"https://github.com/skulpt/skulpt/issues/97","id":17219580,"number":97,"title":"Three-Argument version of type() doesn't work","user":{"login":"l4mpi","id":4486507,"avatar_url":"https://avatars.githubusercontent.com/u/4486507?v=3","gravatar_id":"","url":"https://api.github.com/users/l4mpi","html_url":"https://github.com/l4mpi","followers_url":"https://api.github.com/users/l4mpi/followers","following_url":"https://api.github.com/users/l4mpi/following{/other_user}","gists_url":"https://api.github.com/users/l4mpi/gists{/gist_id}","starred_url":"https://api.github.com/users/l4mpi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l4mpi/subscriptions","organizations_url":"https://api.github.com/users/l4mpi/orgs","repos_url":"https://api.github.com/users/l4mpi/repos","events_url":"https://api.github.com/users/l4mpi/events{/privacy}","received_events_url":"https://api.github.com/users/l4mpi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2013-07-25T15:57:13Z","updated_at":"2015-02-10T09:46:59Z","closed_at":null,"body":"In this example code, the class definition and the `type` call should produce identical classes:\r\n\r\n```python\r\nclass c(object): x = \"bar\"\r\n#c = type(\"c\", (object, ), {\"x\":\"bar\"})\r\ni = c()\r\nprint c, \"\\n\", i, \"\\n\", dir(c)\r\nprint \"attr:\", c.x, i.x\r\n```\r\nThe output using the class statement is as expected:\r\n```\r\n<class '__main__.t'>\r\n<__main__.t object>\r\n['__module__', 'x']\r\nattr: bar bar\r\n```\r\nUncommenting the `type` call yields a dramatically different result:\r\n\r\n```\r\n<class '[object Object]'>\r\n<[object Object] object>\r\n['9', 'get', 'has_key', 'items', 'keys', 'size', 'values']\r\nattr:\r\n```\r\n\r\nI've tried a few more variations of `type` calls, e.g. using an empty tuple for the base classes, and none of them worked, all producing a class with the representation `<class '[object Object]'>`."},"comment":{"url":"https://api.github.com/repos/skulpt/skulpt/issues/comments/73671442","html_url":"https://github.com/skulpt/skulpt/issues/97#issuecomment-73671442","issue_url":"https://api.github.com/repos/skulpt/skulpt/issues/97","id":73671442,"user":{"login":"waywaaard","id":1634468,"avatar_url":"https://avatars.githubusercontent.com/u/1634468?v=3","gravatar_id":"","url":"https://api.github.com/users/waywaaard","html_url":"https://github.com/waywaaard","followers_url":"https://api.github.com/users/waywaaard/followers","following_url":"https://api.github.com/users/waywaaard/following{/other_user}","gists_url":"https://api.github.com/users/waywaaard/gists{/gist_id}","starred_url":"https://api.github.com/users/waywaaard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waywaaard/subscriptions","organizations_url":"https://api.github.com/users/waywaaard/orgs","repos_url":"https://api.github.com/users/waywaaard/repos","events_url":"https://api.github.com/users/waywaaard/events{/privacy}","received_events_url":"https://api.github.com/users/waywaaard/received_events","type":"User","site_admin":false},"created_at":"2015-02-10T09:46:59Z","updated_at":"2015-02-10T09:46:59Z","body":"Ok got a fix for this behavior:\r\n\r\n```python\r\n        // this checks if the dict has been already successfully unwrapped\r\n        // in case of creating classes with class keyword, skulpt automatically\r\n        // unwrap the arguments and sets the module in the buildClass function\r\n        if(dict[\"tp$name\"] && dict[\"tp$name\"] === \"dict\") {\r\n          var it, k;\r\n          for (it = dict.tp$iter(), k = it.tp$iternext(); k !== undefined; k = it.tp$iternext()) {\r\n            v = dict.mp$subscript(k);\r\n            if (v === undefined) {\r\n              v = null;\r\n            }\r\n            klass.prototype[k.v] = v;\r\n            klass[k.v] = v;\r\n          }\r\n\r\n          // set __module__\r\n          dict[\"__module__\"] = Sk.globals[\"__name__\"];\r\n        } else {\r\n          for (v in dict) {\r\n              klass.prototype[v] = dict[v];\r\n              klass[v] = dict[v];\r\n          }\r\n        }\r\n\r\n        // checks if name is builtin type of js object\r\n        if(Sk.builtin.checkString(name)) {\r\n            name = name.v;\r\n        }\r\n\r\n        // unwrap bases if required\r\n        if(bases[\"tp$name\"] && bases[\"tp$name\"] === \"tuple\") {\r\n            bases = bases.v;\r\n        }\r\n```\r\n\r\nThe type() builtin arguments get automatically unwrapped when building a class. If you call type() directly the arguments do not get unwrapped. The above snippet can fix this. However I would be feasible to add a proper check for the ```bases``` argument, hence it has to be of the type tuple.\r\n\r\nAnother thing that I've noticed is, that the ```dir(c)``` behaves not similiar to cpython. It omits attributes in skulpt."}}