René's URL Explorer Experiment


Title: `str()` of an int with exactly `sys.get_int_max_str_digits()` digits raises `ValueError` when its leading digits are large · Issue #9797 · RustPython/RustPython · GitHub

Open Graph Title: `str()` of an int with exactly `sys.get_int_max_str_digits()` digits raises `ValueError` when its leading digits are large · Issue #9797 · RustPython/RustPython

X Title: `str()` of an int with exactly `sys.get_int_max_str_digits()` digits raises `ValueError` when its leading digits are large · Issue #9797 · RustPython/RustPython

Description: Summary Converting an int to a decimal string raises ValueError: Exceeds the limit (4300 digits) for integer string conversion for many ints that have exactly as many digits as the limit. CPython raises only when the result would have mo...

Open Graph Description: Summary Converting an int to a decimal string raises ValueError: Exceeds the limit (4300 digits) for integer string conversion for many ints that have exactly as many digits as the limit. CPython r...

X Description: Summary Converting an int to a decimal string raises ValueError: Exceeds the limit (4300 digits) for integer string conversion for many ints that have exactly as many digits as the limit. CPython r...

Opengraph URL: https://github.com/RustPython/RustPython/issues/9797

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`str()` of an int with exactly `sys.get_int_max_str_digits()` digits raises `ValueError` when its leading digits are large","articleBody":"## Summary\n\nConverting an int to a decimal string raises `ValueError: Exceeds the limit (4300 digits) for integer string conversion` for many ints that have exactly as many digits as the limit. CPython raises only when the result would have more digits than the limit. With the default limit of 4300, `int()` accepts any 4300-digit string, but `str()` of the result fails for every value from `2**14284` (about `8.17e4299`) up, which is about the top 20% of 4300-digit values. So `str(int(s))` does not round-trip for those values. With `sys.set_int_max_str_digits(5000)` the failures start at `2**16609` (about `6.4e4999`), about 40% of 5000-digit values.\n\nThe same happens in `repr()`, f-strings, `format(x, \"d\")`, `format(x, \",\")`, `\"%d\" % x` and `b\"%d\" % x`, and for negative values. Smaller values with the same number of digits, like `2**14284 - 1`, still convert, and so do all values with fewer digits than the limit.\n\nThe [docs](https://docs.python.org/3/library/stdtypes.html#int-max-str-digits) say: \"The limit is applied to the number of digit characters in the input or output string ... When an operation would exceed the limit, a ValueError is raised\".\n\n## Reproducer\n\n```python\nimport sys\n\nprint(sys.get_int_max_str_digits())   # the default limit, 4300\nn = int(\"9\" * 4300)                   # parsing 4300 digits is allowed\nfor x in (n, 2**14284 - 1, 2**14284):\n    try:\n        s = str(x)\n        print(\"ok,\", len(s), \"digits, starts with\", s[:4])\n    except ValueError as e:\n        print(\"ValueError:\", e)\n```\n\n## Expected\n\nCPython 3.15.2 (same on 3.13.18 and 3.12.16):\n\n```\n4300\nok, 4300 digits, starts with 9999\nok, 4300 digits, starts with 8174\nok, 4300 digits, starts with 8174\n```\n\n## Actual\n\nRustPython main (dd8c343), same on a8bd43e and b66534d:\n\n```\n4300\nValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit\nok, 4300 digits, starts with 8174\nValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit\n```\n\n## Cause\n\n`check_int_to_str_digits` ([int.rs#L831-L853](https://github.com/RustPython/RustPython/blob/a8bd43ea1119d660af14528106b659a59837ee0a/crates/vm/src/builtins/int.rs#L831-L853)), added in #7688, estimates the digit count from the bit length as `bits * 30103 / 100_000 + 1` and raises whenever that estimate is over the limit. The estimate is an upper bound and is one too high for the larger values of each digit count. For example, `2**14284` has 14285 bits, so the estimate is 4301, but the value has 4300 digits. CPython also starts with a quick check, but that check only rejects values that are certainly too long. The real comparison is made against the exact length of the converted string ([longobject.c#L2120-L2134](https://github.com/python/cpython/blob/v3.15.2/Objects/longobject.c#L2120-L2134), [#L2207-L2217](https://github.com/python/cpython/blob/v3.15.2/Objects/longobject.c#L2207-L2217)).\n\nThe value has either `digits_upper` or `digits_upper - 1` digits, so one way to fix it is to raise right away only when `digits_upper - 1 > limit`. When `digits_upper == limit + 1`, compare exactly: raise only if `abs(value) >= 10**limit`. I tried this locally. It matched the exact rule (raise only when `len(str(abs(x))) > limit`) on 1,280 values around the boundary for limits 640, 1000, 4300, 5000 and 12345, and `test_int` still passes.\n\nThe existing tests do not catch this. `test_max_str_digits_edge_cases` only converts `10 ** (maxdigits - 1)`, the smallest value with that many digits, and the snippet in `extra_tests/snippets/builtin_int.py` uses `10**4001` (4002 digits) with a limit of 4000.\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-11T08:27:21Z","url":"https://github.com/RustPython/RustPython/issues/9797"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b00839ce-3cc3-5731-9ec2-558560eb4267
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD5B6:3D97C8:2DC8647:3CF6156:6B01D410
html-safe-noncece30d19125ded043ef0b500c70d7d62de15a1b3a6ac5ea0826b94ef4146a1765
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUI2OjNEOTdDODoyREM4NjQ3OjNDRjYxNTY6NkIwMUQ0MTAiLCJ2aXNpdG9yX2lkIjoiMzMyMjMxNTQ0ODAwNDAwNDAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaccf04e5dbad74a05e5b68baa4f9a028b3a8acd61f14b4dcf0109ee7fc6b6dd1f5
hovercard-subject-tagissue:6324603433
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/RustPython/RustPython/9797/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d109cf84ad0cb8bedda2e1c367db6d497c8f2110444ec5ffa9df175532b5cfaa/RustPython/RustPython/issues/9797
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d109cf84ad0cb8bedda2e1c367db6d497c8f2110444ec5ffa9df175532b5cfaa/RustPython/RustPython/issues/9797
og:image:altSummary Converting an int to a decimal string raises ValueError: Exceeds the limit (4300 digits) for integer string conversion for many ints that have exactly as many digits as the limit. CPython r...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametaxor03
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/RustPython/RustPython/issues/9797#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F9797
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F9797
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/issues/9797
Reloadhttps://github.com/RustPython/RustPython/issues/9797
Reloadhttps://github.com/RustPython/RustPython/issues/9797
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests132 (132)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
https://github.com/RustPython/RustPython
New issuehttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/9797
New issuehttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/9797
#9823https://github.com/RustPython/RustPython/pull/9823
str() of an int with exactly sys.get_int_max_str_digits() digits raises ValueError when its leading digits are largehttps://github.com/RustPython/RustPython/issues/9797#top
#9823https://github.com/RustPython/RustPython/pull/9823
https://github.com/taxor03
taxor03https://github.com/taxor03
on Nov 11, 2026https://github.com/RustPython/RustPython/issues/9797#issue-6324603433
docshttps://docs.python.org/3/library/stdtypes.html#int-max-str-digits
dd8c343https://github.com/RustPython/RustPython/commit/dd8c34399621e60e703caeff89b2d5ae5c2f64f6
a8bd43ehttps://github.com/RustPython/RustPython/commit/a8bd43ea1119d660af14528106b659a59837ee0a
b66534dhttps://github.com/RustPython/RustPython/commit/b66534d448f8b94e7874d44ca607c42803c2399f
int.rs#L831-L853https://github.com/RustPython/RustPython/blob/a8bd43ea1119d660af14528106b659a59837ee0a/crates/vm/src/builtins/int.rs#L831-L853
#7688https://github.com/RustPython/RustPython/pull/7688
longobject.c#L2120-L2134https://github.com/python/cpython/blob/v3.15.2/Objects/longobject.c#L2120-L2134
#L2207-L2217https://github.com/python/cpython/blob/v3.15.2/Objects/longobject.c#L2207-L2217
Sign up for freehttps://github.com/signup?return_to=https://github.com/RustPython/RustPython/issues/9797
Sign in to commenthttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/9797
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.