{"action":"closed","issue":{"url":"https://api.github.com/repos/swig/swig/issues/583","labels_url":"https://api.github.com/repos/swig/swig/issues/583/labels{/name}","comments_url":"https://api.github.com/repos/swig/swig/issues/583/comments","events_url":"https://api.github.com/repos/swig/swig/issues/583/events","html_url":"https://github.com/swig/swig/issues/583","id":126042732,"number":583,"title":"SWIG 3.0.8 regression - Python wrapping fails for modules that contain an \"Exception\" class","user":{"login":"benmwebb","id":2257210,"avatar_url":"https://avatars.githubusercontent.com/u/2257210?v=3","gravatar_id":"","url":"https://api.github.com/users/benmwebb","html_url":"https://github.com/benmwebb","followers_url":"https://api.github.com/users/benmwebb/followers","following_url":"https://api.github.com/users/benmwebb/following{/other_user}","gists_url":"https://api.github.com/users/benmwebb/gists{/gist_id}","starred_url":"https://api.github.com/users/benmwebb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benmwebb/subscriptions","organizations_url":"https://api.github.com/users/benmwebb/orgs","repos_url":"https://api.github.com/users/benmwebb/repos","events_url":"https://api.github.com/users/benmwebb/events{/privacy}","received_events_url":"https://api.github.com/users/benmwebb/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-11T21:38:55Z","updated_at":"2016-01-23T23:24:34Z","closed_at":"2016-01-23T23:24:34Z","body":"The following code code can be wrapped just fine with SWIG 3.0.7 but fails with SWIG 3.0.8:\r\n\r\ntest.h:\r\n\r\n    class Exception { };\r\n\r\ntest.i:\r\n\r\n    %module test\r\n    %include \"test.h\"\r\n    %{\r\n    #include \"test.h\"\r\n    %}\r\n\r\nThen compiled with something like `swig -python -c++ test.i && g++ -o _test.so test_wrap.cxx`\r\nand tested with `echo \"import test; t = test.Exception()\" | python`\r\n\r\nThis fails in 3.0.8 because various parts of the SWIG-generated code are protected with `try: ... except Exception:` blocks, and since `Exception` isn't qualified, Python gets confused and thinks you mean the class defined in `test.h`. (3.0.7 does not fail because the protecting block is simply `try: ... except:`.)\r\n\r\nA simple solution would be to use `except __builtins__.Exception` instead, which should be valid Python in Python 1.5 through Python 3.4 at least, or go back to the plain \"except\" block from 3.0.7. I'm happy to create a pull request for either solution if that helps."}}