Title: raise_from does not behave exactly like raise from · Issue #141 · PythonCharmers/python-future · GitHub
Open Graph Title: raise_from does not behave exactly like raise from · Issue #141 · PythonCharmers/python-future
X Title: raise_from does not behave exactly like raise from · Issue #141 · PythonCharmers/python-future
Description: Here's a bit of sample code from [https://www.python.org/dev/peps/pep-3134/](PEP 3134): class DatabaseError(Exception): pass class FileDatabase(object): def __init__(self, filename): try: self.file = open(filename) except IOError as exc:...
Open Graph Description: Here's a bit of sample code from [https://www.python.org/dev/peps/pep-3134/](PEP 3134): class DatabaseError(Exception): pass class FileDatabase(object): def __init__(self, filename): try: self.file...
X Description: Here's a bit of sample code from [https://www.python.org/dev/peps/pep-3134/](PEP 3134): class DatabaseError(Exception): pass class FileDatabase(object): def __init__(self, filename): try: self....
Opengraph URL: https://github.com/PythonCharmers/python-future/issues/141
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"raise_from does not behave exactly like raise from","articleBody":"Here's a bit of sample code from [https://www.python.org/dev/peps/pep-3134/](PEP 3134):\n\n``` python\nclass DatabaseError(Exception):\n pass\n\nclass FileDatabase(object):\n def __init__(self, filename):\n try:\n self.file = open(filename)\n except IOError as exc:\n raise DatabaseError('failed to open') from exc\n\nfd = FileDatabase('dne')\n```\n\nThis, of course, does not work on Python 2. Using Python 3 I get the following output:\n\n```\nTraceback (most recent call last):\n File \"pepex2.py\", line 7, in __init__\n self.file = open(filename)\nFileNotFoundError: [Errno 2] No such file or directory: 'dne'\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"pepex2.py\", line 11, in \u003cmodule\u003e\n fd = FileDatabase('dne')\n File \"pepex2.py\", line 9, in __init__\n raise DatabaseError('failed to open') from exc\n__main__.DatabaseError: failed to open\n```\n\nWhen using `raise_from` for Python2 compatibility\n\n``` python\nfrom future.utils import raise_from\n# [...]\n raise_from(DatabaseError('failed to open'), exc)\n```\n\nthis output (still with Python3) changes to:\n\n```\nFileNotFoundError: [Errno 2] No such file or directory\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"pepex2.py\", line 13, in \u003cmodule\u003e\n fd = FileDatabase('dne')\n File \"pepex2.py\", line 11, in __init__\n raise_from(DatabaseError('failed to open'), exc)\n File \"/home/marc/.virtualenvs/scratch_future3/lib/python3.3/site-packages/future/utils/__init__.py\", line 382, in raise_from\n exec(execstr, myglobals, mylocals)\n File \"\u003cstring\u003e\", line 1, in \u003cmodule\u003e\n__main__.DatabaseError: failed to open\n```\n\nNote that the traceback and exception information are missing from the `FileNotFoundError`.\n","author":{"url":"https://github.com/mbr","@type":"Person","name":"mbr"},"datePublished":"2015-04-25T12:11:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/141/python-future/issues/141"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8d7842d5-1478-6857-a3e3-a376fb75eed2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C948:2004F6:15014DD:1C26EFD:6969B52D |
| html-safe-nonce | 021e64f3882d09bd1f191dd09aa80eeee46cda3a5d2cc8f22b9a23c6ae5b7748 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOTQ4OjIwMDRGNjoxNTAxNEREOjFDMjZFRkQ6Njk2OUI1MkQiLCJ2aXNpdG9yX2lkIjoiOTI5MTE3NTQ2NjI5MTQ5OTk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 056e15067426da8b06933e757027fd665b7dafb0035ef5fbafeecb1a69d0f4fc |
| hovercard-subject-tag | issue:70901235 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PythonCharmers/python-future/141/issue_layout |
| twitter:image | https://opengraph.githubassets.com/01fd7477fdc046917379197fa29708fde203e042290a279963ab61b97b19af7e/PythonCharmers/python-future/issues/141 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/01fd7477fdc046917379197fa29708fde203e042290a279963ab61b97b19af7e/PythonCharmers/python-future/issues/141 |
| og:image:alt | Here's a bit of sample code from [https://www.python.org/dev/peps/pep-3134/](PEP 3134): class DatabaseError(Exception): pass class FileDatabase(object): def __init__(self, filename): try: self.file... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mbr |
| hostname | github.com |
| expected-hostname | github.com |
| None | b23b8fcc855cd29bb04d6c94aafa62d336bf44eefa8229444eecc968cad03aee |
| turbo-cache-control | no-preview |
| go-import | github.com/PythonCharmers/python-future git https://github.com/PythonCharmers/python-future.git |
| octolytics-dimension-user_id | 3365815 |
| octolytics-dimension-user_login | PythonCharmers |
| octolytics-dimension-repository_id | 11403699 |
| octolytics-dimension-repository_nwo | PythonCharmers/python-future |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 11403699 |
| octolytics-dimension-repository_network_root_nwo | PythonCharmers/python-future |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0672399d88424758731ec07fe24509e23bb17fb5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width