Skip to content

Unused variable in except clauses differs between py2 and py3  #301

@moodh

Description

@moodh

The following code gives a warning in py2 but not py3.
But only if the try clause is inside a function, otherwise it passes on both.

test.py:5:25: F841 local variable 'e' is assigned to but never used

def test():
    try:
        raise Exception('foo')
    except Exception as e:
        pass

Is this a bug or a new feature? Could not find anything related to this "regression" but currently py3 does not catch issues py2 would have caught. This is a problem when writing compatible code at the very least.

Could be related to this PR: #59 (found here https://github.com/PyCQA/pyflakes/blob/master/pyflakes/checker.py#L1325)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions