question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enforce stricter slice operations

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sobolevncommented, Nov 19, 2019

Let’s implement several rules that are not bound to types:

  • items[::-1] should not be used. Use reversed or .reverse()
  • items[:] should not be used. Use .copy()
  • items = items[:-1] should not be used. Use items.pop()

@orsinium as always - awesome suggestions! Thanks!

0reactions
orsiniumcommented, Dec 11, 2019

Hmmm, that gives me an idea for one more rule. I’ve made #1071. Thank you, @Eric4Jiang!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Network Slicing and How Does it Work in 5G?
Network slicing overlays multiple virtual networks on top of a shared network domain, that is, a set of shared network and computing resources....
Read more >
Allow optional strict bounds checking for slices #19831 - GitHub
In a more complex application where the slice bounds are calculated to direct operations to specific parts of an array, miscalculating the ...
Read more >
Customized Slicing for 6G: Enforcing Artificial Intelligence on ...
To satisfy stringent requirements of diversified services, network slicing is developed, which enables service-oriented resource allocation ...
Read more >
Network Slicing - an overview | ScienceDirect Topics
Network slicing enables the definition of multiple virtual networks on a ... Network Slicing (NS) wraps a particular global operating system resource to ......
Read more >
5G Slicing: 4 Crucial Principles for Successful Implementation
Operations will be more difficult than creation. More than five domains for network slice management – understanding all five.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found