This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年03月01日 12:14 by a3nm, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| raise.py | a3nm, 2015年03月01日 12:14 | Minimal example | ||
| raise-scope-py3.patch | martin.panter, 2015年07月29日 09:28 | For Python 3 | review | |
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 29236 | merged | kinshukdua, 2021年10月27日 13:10 | |
| PR 30953 | merged | miss-islington, 2022年01月27日 10:24 | |
| PR 30954 | merged | miss-islington, 2022年01月27日 10:25 | |
| Messages (12) | |||
|---|---|---|---|
| msg236957 - (view) | Author: Antoine Amarilli (a3nm) | Date: 2015年03月01日 12:14 | |
Hello, Python 2.7.8 and Python 3.4.2 (from Debian testing) have a different behavior on the attached file. Python 2 raises "bar", Python 3 raises "foo". I can't find an adequate explanation in the documentation for this behavior difference. It probably relates to https://docs.python.org/3/reference/compound_stmts.html#try (search for "When an exception has been assigned") but this is unsatisfying because it only talks about the "as target" construction, which is not used in the example. I think that at least the documentation should be clarified to point out what "raise" without arguments will do. Currently the documentation of this in Python 2 and 3 is the same even though the behavior is different https://docs.python.org/2/reference/simple_stmts.html#raise https://docs.python.org/3/reference/simple_stmts.html#raise. Note: this question was originally asked on SO: http://stackoverflow.com/q/28698622/414272. I reported this as a bug at Terry Jan Reedy's request https://stackoverflow.com/q/28698622/414272#comment45707744_28698622. |
|||
| msg236959 - (view) | Author: SilentGhost (SilentGhost) * (Python triager) | Date: 2015年03月01日 12:23 | |
There is this bit in https://docs.python.org/3/library/exceptions.html : > When raising a new exception (rather than using a bare raise to re-raise the exception currently being handled),... I presume this can be also suitable for tutorial if it's not already there. |
|||
| msg237493 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年03月08日 01:49 | |
For the Python 3 case, the documentation is vague and probably wrong, depending on what you understand "the current scope" to mean. I think it should read something like . . . raise re-raises the current exception that is being handled. If no exception is being handled, a RuntimeError exception is raised indicating that this is an error. I’m not sure but I suspect Python 2 is different because does not save the original exception when it handles a nested exception. In other words, at the point where the nested "bar" exception is raised inside the "foo" handler, Python forgets that "foo" was being handled. |
|||
| msg247563 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年07月29日 09:28 | |
Here is a patch for Python 3. The re-raise behaviour reported by Antoine is already tested in test_raise.TestRaise.test_except_reraise(). My patch also clarifies some details about how __context__ is set: * Context is the exception being handled, not necessarily the last exception * "With" statements can influence context * Re-raising does not set context; must be new exception object * Add test case when context is not the last exception I’m not so experienced with Python 2’s exception handling, so I haven’t got a patch for that. I suspect there is some shared "last exception" context. I wonder how it interacts with generators, multi-threading, __del__() and other callbacks, etc. |
|||
| msg256907 - (view) | Author: John Mark Vandenberg (jayvdb) * | Date: 2015年12月23日 11:23 | |
In pyflakes we've looked at some of the strange scenarios where a raise without argument is 'legal'. A patch to report errors for some of these was rejected because they are legal. See https://github.com/pyflakes/pyflakes/pull/57 The worst example of 'legal' is an exception in one module can be re-raised by another module. |
|||
| msg405000 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2021年10月25日 21:00 | |
Martin's patch needs to be converted to a GitHub PR and then reviewed. |
|||
| msg411679 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2022年01月25日 22:28 | |
@kinshukdua - can you explain why you closed the PR and whether you are interested in reopening it and finishing this? |
|||
| msg411735 - (view) | Author: Kinshuk Dua (kinshukdua2) * | Date: 2022年01月26日 10:46 | |
@iritkatriel I thought the PR won't be reviewed after being marked as stale that's why I closed it. I've reopened it and I'm interested in finishing it. |
|||
| msg411848 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2022年01月27日 10:25 | |
New changeset 08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85 by Kinshuk Dua in branch 'main': bpo-23556: [doc] Fix inaccuracy in documentation for raise without args. Improve tests for context in nested except handlers. (GH-29236) https://github.com/python/cpython/commit/08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85 |
|||
| msg411852 - (view) | Author: miss-islington (miss-islington) | Date: 2022年01月27日 10:51 | |
New changeset 1440dd343871645c187028916dd6ee97300d2557 by Miss Islington (bot) in branch '3.9': bpo-23556: [doc] Fix inaccuracy in documentation for raise without args. Improve tests for context in nested except handlers. (GH-29236) https://github.com/python/cpython/commit/1440dd343871645c187028916dd6ee97300d2557 |
|||
| msg411853 - (view) | Author: miss-islington (miss-islington) | Date: 2022年01月27日 10:51 | |
New changeset 2572c670d42887e4b1d2475b8da2e9bf6e0aa558 by Miss Islington (bot) in branch '3.10': [3.10] bpo-23556: [doc] Fix inaccuracy in documentation for raise without args. Improve tests for context in nested except handlers. (GH-29236) (GH-30953) https://github.com/python/cpython/commit/2572c670d42887e4b1d2475b8da2e9bf6e0aa558 |
|||
| msg411854 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2022年01月27日 10:52 | |
Thank you @a3nm, @kinshukdua2 and @martin.panter. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:13 | admin | set | github: 67744 |
| 2022年01月27日 10:52:25 | iritkatriel | set | status: open -> closed resolution: fixed messages: + msg411854 stage: patch review -> resolved |
| 2022年01月27日 10:51:10 | miss-islington | set | messages: + msg411853 |
| 2022年01月27日 10:51:06 | miss-islington | set | messages: + msg411852 |
| 2022年01月27日 10:25:01 | iritkatriel | set | messages: + msg411848 |
| 2022年01月27日 10:25:01 | miss-islington | set | pull_requests: + pull_request29133 |
| 2022年01月27日 10:24:56 | miss-islington | set | nosy:
+ miss-islington pull_requests: + pull_request29132 |
| 2022年01月26日 10:46:41 | kinshukdua2 | set | nosy:
+ kinshukdua2 messages: + msg411735 |
| 2022年01月25日 22:28:25 | iritkatriel | set | messages: + msg411679 |
| 2021年10月27日 13:10:44 | kinshukdua | set | keywords:
+ patch nosy: + kinshukdua pull_requests: + pull_request27499 |
| 2021年10月25日 21:00:36 | iritkatriel | set | nosy:
+ iritkatriel versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.4, Python 3.5, Python 3.6 messages: + msg405000 keywords: + easy, - patch title: Scope for raise without argument is different in Python 2 and 3 -> [doc] Scope for raise without argument is different in Python 2 and 3 |
| 2015年12月23日 11:23:08 | jayvdb | set | nosy:
+ jayvdb messages: + msg256907 |
| 2015年07月29日 09:28:16 | martin.panter | set | files:
+ raise-scope-py3.patch versions: + Python 3.5, Python 3.6 messages: + msg247563 keywords: + patch stage: patch review |
| 2015年07月21日 07:23:29 | ethan.furman | set | nosy:
- ethan.furman |
| 2015年03月14日 00:13:44 | ethan.furman | set | nosy:
+ ethan.furman |
| 2015年03月08日 01:49:34 | martin.panter | set | assignee: docs@python components: + Documentation nosy: + docs@python |
| 2015年03月08日 01:49:13 | martin.panter | set | messages: + msg237493 |
| 2015年03月01日 21:39:27 | martin.panter | set | nosy:
+ martin.panter |
| 2015年03月01日 12:26:36 | SilentGhost | set | nosy:
+ collinwinter |
| 2015年03月01日 12:23:21 | SilentGhost | set | nosy:
+ SilentGhost messages: + msg236959 components: + Interpreter Core |
| 2015年03月01日 12:14:32 | a3nm | create | |