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.

Forbid explicit step in slice

See original GitHub issue

Rule request

Thesis

# bad
a[1:4:]
# good
a[1:4]

# bad
a[1::]
# good
a[1:]

# bad
a[1:4:1]
# good
a[1:4]

# bad
a[1::1]
# good
a[1:]

# bad
a[::1]
# good
a.copy()

Case with a[::] will be covered in #1011

Reasoning

Consistency

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
skarzicommented, Jan 27, 2020

So, why could we want to use [::] on it if it is immutable? Also, you can always use copy.copy function for custom collections (than does nothing for tuples as well, btw).

True, it doesn’t make much sense when we are talking about immutable objects, I just wanted to give some example that .copy() is not a good solution, however I agree that copy.copy() is.

As you said, we can’t say the difference between a[:] and a[::]. So we can’t suggest using one instead of others.

If we decide to write token visitor instead of AST, it will be possible to distinguish cases like 1st and 2nd ones, but I need to do some research and experiments to fully confirm that.

1reaction
orsiniumcommented, Jan 27, 2020

I concluded that for 1st and 2nd case the AST looks identical

Let’s for the beginning cover remaining cases. It’s better than nothing.

tuple is immutable so it doesn’t have such method

So, why could we want to use [::] on it if it is immutable? Also, you can always use copy.copy function for custom collections (than does nothing for tuples as well, btw).

however we can still suggest to use a[:]

As you said, we can’t say the difference between a[:] and a[::]. So we can’t suggest using one instead of others.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issuehunt
You can request for a bounty in order to promote it! Request a bounty. Forbid explicit step in slice #1071.
Read more >
Indexing and Selecting in Pandas - slicing - wrighters.io
If you instantiante a slice object explicitly, you can supply a single value (the stop), or you can supply the start and stop...
Read more >
0198-slice-notation - The Rust RFC Book
One way of solving this problem is for the slice methods to take self (by value) rather than &self , and in turn...
Read more >
Extended slice that goes to beginning of sequence with ...
My question is: Is there any good pythonic way of using extended slices with negative strides and explicit start and end indices that...
Read more >
PDL::Slices - Indexing, slicing, and dicing - metacpan.org
If you specify no boundary conditions the default is to forbid boundary violations on all axes. ... <n>:<m>:<s> -- select a range with...
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