Skip to content

Refactor redundant slice indices to use concise slice notation #331

@sourcery-ai

Description

@sourcery-ai

The codebase currently contains redundant slice indices in some list or string slicing operations. Specifically, there are instances where a[0:x] is used instead of the more concise a[:x], and a[x:len(a)] is used instead of a[x:]. This was highlighted by Sourcery's remove-redundant-slice-index rule.

For example, the following code:

if isinstance(ds, str) and ds[0:3] == "sr-":

should be refactored to:

if isinstance(ds, str) and ds[:3] == "sr-":

Action Items:

  • Search the codebase for instances of redundant slice indices (e.g., [0:x] and [x:len(a)]).
  • Refactor them to use the more concise slice notation ([:x] and [x:]).
  • Ensure all tests pass after making these changes.

This will improve code readability and maintainability.


I created this issue for @sjswerdloff from #328 (comment).

Tips and commands

Getting Help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions