Skip to content

new rule - zero step in slice #3768

Closed
Closed

Description

@DetachHead

https://docs.astral.sh/ty/reference/rules/#zero-stepsize-in-slice

l = list(range(10))
l[1:10:0]  # ValueError: slice step cannot be zero

(sorry for raising so many issues, i'm working on a rule comparison table between all the type checkers and opening issues for each rule missing between ty/pyrefly/basedpyright. i think this is the last one for pyrefly!)

Activity

  1. jorenham commented on Jun 11, 2026

    @jorenham
    Collaborator

    Pyrefly also does not report anything here:

    >>> l = list(range(10))
    >>> l[1: 10: 0.5]
    Traceback (most recent call last):
      File "<python-input-2>", line 1, in <module>
        l[1:10:1.5]
        ~^^^^^^^^^^
    TypeError: slice indices must be integers or None or have an __index__ method

    https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIUABALxVQRwAuAFAE4YDmMLAjAAwBKQQB10UANq9EVATN6EArAF0QAXwA0IVAGMmEAG4wAYtBgU0WPETLqgA

  2. yangdanny97 commented on Jun 11, 2026

    @yangdanny97
    Collaborator

    sorry for raising so many issues, i'm working on a rule comparison table between all the type checkers and opening issues for each rule missing between ty/pyrefly/basedpyright. i think this is the last one for pyrefly!

    Thanks for that! We appreciate the thoroughness and these issues are really helpful

  3. added
    help wantedLarger than "good first issue", but still well-defined and ready for someone to pick up
    on Jun 11, 2026
  4. DetachHead commented on Jun 13, 2026

    @DetachHead
    ContributorAuthor
  5. ak4-sh commented on Jun 13, 2026

    @ak4-sh
    Contributor

    @yangdanny97 Can I give this a go?

  6. ak4-sh commented on Jun 13, 2026

    @ak4-sh
    Contributor

    From what I see, Pyrefly doesn't report any issues when we have a decimal in the step variable, but we do check for the start index and end index. Sandbox link

  7. jorenham commented on Jun 13, 2026

    @jorenham
    Collaborator

    FWIW; this doesn't seem to be a typeshed issue, which uses slice[SupportsIndex | None] for list.__getitem__:

    https://github.com/python/typeshed/blob/feeb9aa8dde3ae9269b13f3bae435b82d8538b76/stdlib/builtins.pyi#L1250-L1253

  8. ak4-sh commented on Jun 24, 2026

    @ak4-sh
    Contributor

    I'll give this a go then! #claim

  9. github-actions commented on Jun 24, 2026

    @github-actions

    @ak4-sh you've claimed this issue — it's now assigned to you. Thanks for picking it up! 🎉

  10. github-actions commented on Jul 11, 2026

    @github-actions

    This issue has someone assigned, but has not had recent activity for more than 2 weeks.

    If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.

    Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wantedLarger than "good first issue", but still well-defined and ready for someone to pick upstaletypechecking

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions