{"action":"opened","issue":{"url":"https://api.github.com/repos/mapleoin/undecorated/issues/1","repository_url":"https://api.github.com/repos/mapleoin/undecorated","labels_url":"https://api.github.com/repos/mapleoin/undecorated/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/mapleoin/undecorated/issues/1/comments","events_url":"https://api.github.com/repos/mapleoin/undecorated/issues/1/events","html_url":"https://github.com/mapleoin/undecorated/issues/1","id":188838436,"number":1,"title":"Can't undecorate when decorated function is a closure itself","user":{"login":"six8","id":361145,"avatar_url":"https://avatars.githubusercontent.com/u/361145?v=3","gravatar_id":"","url":"https://api.github.com/users/six8","html_url":"https://github.com/six8","followers_url":"https://api.github.com/users/six8/followers","following_url":"https://api.github.com/users/six8/following{/other_user}","gists_url":"https://api.github.com/users/six8/gists{/gist_id}","starred_url":"https://api.github.com/users/six8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/six8/subscriptions","organizations_url":"https://api.github.com/users/six8/orgs","repos_url":"https://api.github.com/users/six8/repos","events_url":"https://api.github.com/users/six8/events{/privacy}","received_events_url":"https://api.github.com/users/six8/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-11T20:00:20Z","updated_at":"2016-11-11T20:00:20Z","closed_at":null,"body":"When you decorate a function that is defined within another function and it references variables within the enclosing function (in other words, when you decorate a closure), you can't undecorate it.\r\n\r\n```\r\ndef decorator(o):\r\n    def foo():\r\n        return o()\r\n    return foo\r\n\r\ndef factory():\r\n    outside = object()\r\n\r\n    @decorator\r\n    def internal_reference():\r\n        inside = object()\r\n        print inside\r\n\r\n    @decorator\r\n    def external_reference():\r\n        return outside\r\n\r\n    print undecorated(internal_reference)\r\n    print undecorated(external_reference)\r\n\r\nfactory()\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n<function internal_reference at 0x10c30e2a8>\r\nNone\r\n```\r\n\r\nI couldn't find a way around this other than \"don't do it\". I ran it to while using a factory function for unit tests. This isn't typical usage of Python though."}}
{"actor":{"display_login":"six8"}}