Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
correctmost opened this issue Apr 10, 2025 · 1 comment · Fixed by #10350
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@correctmost
Copy link
Contributor

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

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Apr 10, 2025
@cdce8p
Copy link
Member

cdce8p commented Apr 10, 2025

Note that slice itself is not a callable, so the code above would fail in production as well.

>>> slice(-2)()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    slice(-2)()
    ~~~~~~~~~^^
TypeError: 'slice' object is not callable

codegen-sh bot added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2025
codegen-sh bot added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2025
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2025
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2025
Closes pylint-dev#10334

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
Pierre-Sassoulas pushed a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2025
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2025
Closes pylint-dev#10334

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2025
Closes pylint-dev#10334

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants