Skip to content

2to3 doesn't detect or fix Exception indexing #74424

Closed

Description

@dlenski
mannequin
BPO 30238
Nosy @benjaminp, @dlenski, @tirkarthi, @iritkatriel
Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-10-20.22:53:12.404>
    created_at = <Date 2017-05-02.19:31:56.005>
    labels = ['type-feature', 'expert-2to3']
    title = "2to3 doesn't detect or fix Exception indexing"
    updated_at = <Date 2021-10-21.04:48:00.651>
    user = 'https://github.com/dlenski'

    bugs.python.org fields:

    activity = <Date 2021-10-21.04:48:00.651>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:53:12.404>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2017-05-02.19:31:56.005>
    creator = 'dlenski'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30238
    keywords = []
    message_count = 5.0
    messages = ['292799', '396172', '396289', '404561', '404566']
    nosy_count = 4.0
    nosy_names = ['benjamin.peterson', 'dlenski', 'xtreak', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30238'
    versions = ['Python 2.7']

    Activity

    1. dlenski commented on May 2, 2017

      dlenskimannequin
      MannequinAuthor

      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.

    2. iritkatriel commented on Jun 20, 2021

      @iritkatriel
      Member

      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.

    3. dlenski commented on Jun 21, 2021

      dlenskimannequin
      MannequinAuthor

      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.

    4. dlenski commented on Oct 21, 2021

      dlenskimannequin
      MannequinAuthor

      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.

    5. benjaminp commented on Oct 21, 2021

      @benjaminp
      Contributor

      See the superseding issue; 2to3 is deprecated and headed towards deletion.

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions