Title: `sys.setswitchinterval()` rejects a `Fraction` or `Decimal` interval · Issue #9970 · RustPython/RustPython · GitHub
Open Graph Title: `sys.setswitchinterval()` rejects a `Fraction` or `Decimal` interval · Issue #9970 · RustPython/RustPython
X Title: `sys.setswitchinterval()` rejects a `Fraction` or `Decimal` interval · Issue #9970 · RustPython/RustPython
Description: Summary sys.setswitchinterval() accepts only a float. CPython converts any object that defines __float__, so a Fraction or Decimal interval works there and raises TypeError on RustPython. Reproducer import sys from fractions import Fract...
Open Graph Description: Summary sys.setswitchinterval() accepts only a float. CPython converts any object that defines __float__, so a Fraction or Decimal interval works there and raises TypeError on RustPython. Reproduce...
X Description: Summary sys.setswitchinterval() accepts only a float. CPython converts any object that defines __float__, so a Fraction or Decimal interval works there and raises TypeError on RustPython. Reproduce...
Opengraph URL: https://github.com/RustPython/RustPython/issues/9970
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`sys.setswitchinterval()` rejects a `Fraction` or `Decimal` interval","articleBody":"## Summary\n\n`sys.setswitchinterval()` accepts only a `float`. CPython converts any object that defines `__float__`, so a `Fraction` or `Decimal` interval works there and raises `TypeError` on RustPython.\n\n## Reproducer\n\n```python\nimport sys\nfrom fractions import Fraction\nfrom decimal import Decimal\n\nold = sys.getswitchinterval()\nfor x in (Fraction(1, 500), Decimal(\"0.002\")):\n try:\n sys.setswitchinterval(x)\n print(type(x).__name__, sys.getswitchinterval())\n except Exception as e:\n print(type(x).__name__, type(e).__name__, e)\nsys.setswitchinterval(old)\n```\n\n## Expected\n\nCPython 3.14.6:\n\n```\nFraction 0.002\nDecimal 0.002\n```\n\n## Actual\n\nRustPython main (c4b303d):\n\n```\nFraction TypeError Expected type 'float' but 'Fraction' found.\nDecimal TypeError Expected type 'float' but 'Decimal' found.\n```\n\n## Cause\n\n`setswitchinterval` takes `interval: f64` ([sys.rs#L1678](https://github.com/RustPython/RustPython/blob/c4b303dcfae249899417e5b31de0f5c8629d27ec/crates/vm/src/stdlib/sys.rs#L1678)), and that conversion accepts only a `float`. CPython's argument clinic code converts the argument with `PyFloat_AsDouble()` ([sysmodule.c.h#L526](https://github.com/python/cpython/blob/v3.14.6/Python/clinic/sysmodule.c.h#L526)), which calls `__float__`.\n\n\u003csub>Drafted with help from Claude Code; I reviewed and checked it before posting.\u003c/sub>\n","author":{"url":"https://github.com/taxor03","@type":"Person","name":"taxor03"},"datePublished":"2026-11-19T16:01:20Z","url":"https://github.com/RustPython/RustPython/issues/9970"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:95dff962-d954-7923-147f-e3b9515da52b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8654:31D532:E493BE:12F597F:6B01D40E |
| html-safe-nonce | 175818c42e3409c173c209e8863ab83866500aacdce32340651da0e98c220bcf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjU0OjMxRDUzMjpFNDkzQkU6MTJGNTk3Rjo2QjAxRDQwRSIsInZpc2l0b3JfaWQiOiI4ODM3MjE4MDE0NDY3MzE0NzAyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | dc70826578c6df998c2f9348d35095b7178744a8956f5a19db41f7f96c5fc701 |
| hovercard-subject-tag | issue:6493669776 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/RustPython/RustPython/9970/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6e09ee40a86401cdf8cc915645f993b9891651ff87fc6b8e53d6b9cb22638e93/RustPython/RustPython/issues/9970 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6e09ee40a86401cdf8cc915645f993b9891651ff87fc6b8e53d6b9cb22638e93/RustPython/RustPython/issues/9970 |
| og:image:alt | Summary sys.setswitchinterval() accepts only a float. CPython converts any object that defines __float__, so a Fraction or Decimal interval works there and raises TypeError on RustPython. Reproduce... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | taxor03 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width