You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
2to3 doesn't detect or fix Exception indexing #74424
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.
Activity
dlenski commentedon May 2, 2017
Python 2.7 allows indexing an Exception object to access its args list.
This doesn't work in 3.5:
This conversion (e[x] -> e.args[x]) seems like it ought to be fairly straightforward to support in 2to3.
iritkatriel commentedon Jun 20, 2021
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.
dlenski commentedon Jun 21, 2021
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.
dlenski commentedon Oct 21, 2021
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.
benjaminp commentedon Oct 21, 2021
See the superseding issue; 2to3 is deprecated and headed towards deletion.