Skip to content

Enforce stricter slice operations #1011

@orsinium

Description

@orsinium

Rule request

Thesis

The list has a set of methods that duplicates operations that you can do with + operator or slices:

# bad
items += [item]
# good
items.append(item)

# bad
items = [item] + items
# good
items.insert(0, item)

# bad
items += other
# good
items.extend(other)

# bad
items = items[::-1]
# good
items.reverse()

# bad
items = sorted(items)
# good
items.sort()

# bad
other = items[:]
# good
other = items.copy()

# bad
items[:] = []
# good
items.clear()

# bad
items = items[:-1]
# good
items.pop()

Reasoning

We have two ways to do something. Let's prefer a more descriptive way.

This issue contains a lot of related cases. Consider splitting it by smaller ones.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions