Skip to content

Not reporting W0621 redefined-outer-name when the outer name is redefined by except .. as .. #4434

Closed
@chucklin

Description

@chucklin

Steps to reproduce

Given a file a.py:

"""Test pylint W0621"""
class CustomException(Exception):
    """Customized Exception"""

def func():
    """Override CustomException by except .. as .."""
    try:
        raise CustomException('Test')
    except IOError as CustomException:
        pass

Current behavior

Result of pylint a.py:

************* Module test
test.py:8:14: E0601: Using variable 'CustomException' before assignment (used-before-assignment)

------------------------------------------------------------------
Your code has been rated at 1.67/10 (previous run: 1.67/10, +0.00)

Expected behavior

Expecting pylint reports W0621 redefined-outer-name on line except IOError as CustomException

I tested overriding the outer name by with .. as .., and the W0621 reported without problems.
In my opinion, W0621 should also be reported when the outer name gets redefined by except .. as .. .

pylint --version output

Result of pylint --version output:

pylint 2.8.2
astroid 2.5.6
Python 3.9.2 (default, Apr 12 2021, 14:14:14)
[Clang 12.0.0 (clang-1200.0.32.29)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentFalse Negative 🦋No message is emitted but something is wrong with the codeFalse Positive 🦟A message is emitted but nothing is wrong with the code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions