Issue30238
Created on 2017-05-02 19:31 by dlenski, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg292799 - (view) | Author: Daniel Lenski (dlenski) * | Date: 2017-05-02 19:31 | |
Python 2.7 allows indexing an Exception object to access its args list.
>>> e=Exception('foo','bar','baz')
>>> assert e[0] is e.args[0]
This doesn't work in 3.5:
>>> e=Exception('foo','bar','baz')
>>> e.args[0]
'foo'
>>> e[0]
TypeError: 'Exception' object is not subscriptable
This conversion (e[x] -> e.args[x]) seems like it ought to be fairly straightforward to support in 2to3.
|
|||
| msg396172 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2021-06-20 14:35 | |
There is no way to know through static analysis that the subscript is on an object of type exception. I think this should be closed as won't fix. |
|||
| msg396289 - (view) | Author: Daniel Lenski (dlenski) * | Date: 2021-06-21 21:14 | |
> There is no way to know through static analysis that the subscript is on an object of type exception. I think this should be closed as won't fix.
In almost all cases, the variable in question will receive its value via `except ... as e:`.
try:
...
except (Exception1, Exception2, ...) as e:
e[0]
Seems to me that it should be possible for 2to3 to handle this large subset of applicable cases via static analysis.
|
|||
| msg404561 - (view) | Author: Daniel Lenski (dlenski) * | Date: 2021-10-21 01:25 | |
Why was this closed? As I wrote in a previous comment, this situation can be automatically identified and addressed via static analysis in the vastly-predominant case, where the Exception object is assigned via an `exception ... as exc:` clause. |
|||
| msg404566 - (view) | Author: Benjamin Peterson (benjamin.peterson) * ![]() |
Date: 2021-10-21 04:48 | |
See the superseding issue; 2to3 is deprecated and headed towards deletion. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:45 | admin | set | github: 74424 |
| 2021-10-21 04:48:00 | benjamin.peterson | set | messages: + msg404566 |
| 2021-10-21 01:25:46 | dlenski | set | messages: + msg404561 |
| 2021-10-20 22:53:12 | iritkatriel | set | status: open -> closed superseder: Close 2to3 issues and list them here stage: test needed -> resolved |
| 2021-06-21 21:14:18 | dlenski | set | status: pending -> open messages: + msg396289 |
| 2021-06-20 14:35:05 | iritkatriel | set | status: open -> pending nosy:
+ iritkatriel resolution: wont fix |
| 2018-09-11 10:02:13 | xtreak | set | nosy:
+ xtreak |
| 2017-05-05 22:11:14 | terry.reedy | set | nosy:
+ benjamin.peterson stage: test needed |
| 2017-05-02 19:31:56 | dlenski | create | |
