← 输入框|github.com|刷新
Skip to content

time.sleep(-1.0) causes panic #5895

Description

@youknowone

Summary

https://github.com/RustPython/RustPython/pull/5892/files#r2183174081

import time
time.sleep(-1)

Expected

raise exception

Actual

panic

Python Documentation

Activity

  1. added theissue type on Jul 4, 2025
  2. DominicPrince2003 commented on Jul 5, 2025

    @DominicPrince2003

    Hi, can I take up this issue?

    I'm planning to modify the time.sleep() implementation to safely handle:

    • Negative values

    Proposed solution:

    • Modify the dur type to f64 insted of Duration
    • Validate the f64 input before conversion
    • Raise a ValueError if the input is invalid
    • For valid values, use Duration::from_secs_f64()

    Let me know if this approach is okay.

  3. youknowone commented on Jul 6, 2025

    @youknowone
    MemberAuthor

    Yes, that's one of the possible solutions. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions