Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Release date: TBA

Closes #2734

* Fix a crash when parsing a slice called in a decorator on a function that is also decorated with
a known ``six`` decorator.

Closes #2721

What's New in astroid 3.3.10?
=============================
Release date: 2025-05-10
Expand Down
6 changes: 5 additions & 1 deletion astroid/brain/brain_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ def transform_six_add_metaclass(node): # pylint: disable=inconsistent-return-st
func = next(decorator.func.infer())
except (InferenceError, StopIteration):
continue
if func.qname() == SIX_ADD_METACLASS and decorator.args:
if (
isinstance(func, (nodes.FunctionDef, nodes.ClassDef))
and func.qname() == SIX_ADD_METACLASS
and decorator.args
):
metaclass = decorator.args[0]
node._metaclass = metaclass
return node
Expand Down
16 changes: 16 additions & 0 deletions tests/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,19 @@ def test_regression_no_crash_during_build() -> None:
node: nodes.Attribute = extract_node("__()")
assert node.args == []
assert node.as_string() == "__()"


def test_regression_no_crash_on_called_slice() -> None:
"""Regression test for issue #2721."""
node: nodes.Attribute = extract_node(
textwrap.dedent(
"""
s = slice(-2)
@s()
@six.add_metaclass()
class a: ...
"""
)
)
assert isinstance(node, nodes.ClassDef)
assert node.name == "a"