Skip to content

AttributeError: 'Slice' object has no attribute 'name' when a slice is used as a class decorator #10334

Closed
@correctmost

Description

@correctmost

Bug description

While triaging pylint-dev/astroid#2721, I triggered an AttributeError in Pylint:

s = slice(-2)
@s()
class a: ...

Here's a similar issue that was fixed: #8067

Configuration

Command used

pylint crash.py

Pylint output

Exception on node <ClassDef.a l.3 at 0x72df671d8690> in file 'crash.py'
Traceback (most recent call last):
  File "pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
  File "pylint/checkers/base/basic_error_checker.py", line 212, in visit_classdef
    self._check_redefinition("class", node)
  File "pylint/checkers/base/basic_error_checker.py", line 518, in _check_redefinition
    defined_self = next(
                   ^^^^^
  File "pylint/checkers/base/basic_error_checker.py", line 519, in <genexpr>
    (local for local in redefinitions if not utils.is_overload_stub(local)),
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint/checkers/utils.py", line 1676, in is_overload_stub
    return bool(decorators and decorated_with(node, ["typing.overload", "overload"]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint/checkers/utils.py", line 875, in decorated_with
    if any(
       ^^^^
  File "pylint/checkers/utils.py", line 876, in <genexpr>
    i.name in qnames or i.qname() in qnames
    ^^^^^^
AttributeError: 'Slice' object has no attribute 'name'

Expected behavior

No crash

Pylint version

pylint: 70559b8
astroid: pylint-dev/astroid@ce81c290efa
Python 3.13.2

OS / Environment

Arch Linux

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions