René's URL Explorer Experiment


Title: FR: Change `int` repr on huge values to automatically use hexadecimal · Issue #96601 · python/cpython · GitHub

Open Graph Title: FR: Change `int` repr on huge values to automatically use hexadecimal · Issue #96601 · python/cpython

X Title: FR: Change `int` repr on huge values to automatically use hexadecimal · Issue #96601 · python/cpython

Description: Problem Now that 95778 is in, the repr of an int can fail with a ValueError based on its size because repr and str are the same for int thus huge values cannot have a repr. We discussed this while working on that security fix but deemed ...

Open Graph Description: Problem Now that 95778 is in, the repr of an int can fail with a ValueError based on its size because repr and str are the same for int thus huge values cannot have a repr. We discussed this while ...

X Description: Problem Now that 95778 is in, the repr of an int can fail with a ValueError based on its size because repr and str are the same for int thus huge values cannot have a repr. We discussed this while ...

Opengraph URL: https://github.com/python/cpython/issues/96601

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"FR: Change `int` repr on huge values to automatically use hexadecimal","articleBody":"# Problem\r\n\r\nNow that [95778](https://github.com/python/cpython/issues/95778) is in, the `repr` of an `int` can fail with a ValueError based on its size because `repr` and `str` are the same for `int` thus huge values cannot have a repr.\r\n\r\nWe discussed this while working on that security fix but deemed that changing a repr was way beyond reason for a patch release bugfix. Raising the ValueError exception highlights the point in the code that potentially needs specific attention rather than allowing a new unexpected format of data to start showing up where it hadn't previously as a result of a patch release.\r\n\r\n# Enhancement Proposal\r\n\r\nWe could fix this annoyance if we are willing to change `int`'s repr. For huge values we could automatically repr them as hexadecimal.  **`str` behavior would not change.**\r\n\r\nThe auto-hex repr point needs to be at less bits than required to represent a `sys.int_info.str_digits_check_threshold` decimal digit value so that there exists no scenario in which `repr` of an `int` could fail.\r\n\r\n```python\r\n\u003e\u003e\u003e int('1'+('0'*(sys.int_info.str_digits_check_threshold-1))).bit_count()\r\n738\r\n\u003e\u003e\u003e int('1'+('0'*(sys.get_int_max_str_digits()-1))).bit_count()\r\n4966\r\n```\r\n\r\nPerhaps all integers \u003e512 bits (to pick an arbitrary nice threshold) could repr to hexadecimal:\r\n\r\n```python\r\n\u003e\u003e\u003e 2**511\r\n6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048\r\n\u003e\u003e\u003e 2**513\r\n0x200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n\u003e\u003e\u003e str(2**513)\r\n'26815615859885194199148049996411692254958731641184786755447122887443528060147093953603748596333806855380063716372972101707507765623893139892867298012168192'\r\n```\r\n\r\nEffectively this behavior:\r\n\r\n```python\r\ndef proposed_int_repr(value: int):\r\n    if value.bit_count() \u003c= 512:\r\n        return repr(value)\r\n    else:\r\n        return hex(value)\r\n```\r\n\r\n## Potential wins\r\n\r\n1) We return to **always** being able to `repr` an `int` other than a MemoryError.\r\n2) Less hacky code is needed to see the actual value of an `int` when it is huge. Notebook users for example would see the result of their huge `int` computation instead of a ValueError. It'd just be in hex. (REPLs emit the repr)\r\n   On the other hand, I expect notebooks may choose to implement this in their own REPL repr code long before it is released into a CPython version that they're run on top of.\r\n3) People don't need to check for `int` and implement their own specialized repr when they _always want_ a value.\r\n4) _Minor_: People start using hexadecimal constants for huge values in code rather than decimal when they pasted them in from a REPL. Faster parsing, shorter code.\r\n\r\n## Potential disruption\r\n\r\n1) Golden value tests comparing string form data.\r\n2) Code inadvertently using the `repr` expecting to always get a decimal value. Bug in user code: Should use `str`.\r\n3) Stored reprs of data consumed at a distance by other code where it previously contained decimal values. Bug in user code: repr is not a data storage and transmission format.\r\n\r\nIf we didn't choose a low limit, but instead tied the switch over point to the largest binary value that fits within `sys.get_int_str_max_digits()` decimal digits we'd be inconsistent between environments or programs that choose to change their digits limit but would avoid emitting hexadecimal unless we had no other choice. This variant could be thought of as:\r\n\r\n```python\r\ndef digit_limit_tied_proposed_int_repr(value: int):\r\n    try:\r\n        return repr(value)\r\n    except ValueError:\r\n        return hex(value)\r\n```\r\n\r\n","author":{"url":"https://github.com/gpshead","@type":"Person","name":"gpshead"},"datePublished":"2022-09-05T19:58:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/96601/cpython/issues/96601"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:077b872f-d8e0-4e49-4771-a18d94e68b53
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id85E2:17997A:9303CD:C56173:6969BF5D
html-safe-nonce282e734f4b27d36da9b855d44fd4c3d16a5fc635ef924754206e792bef3e2c82
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUUyOjE3OTk3QTo5MzAzQ0Q6QzU2MTczOjY5NjlCRjVEIiwidmlzaXRvcl9pZCI6IjcxNTY2MDI0MjI1MjY4NTI5NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac9b8e9a8c3cb3a182ce811e4423279f07949e4d3b51f62e104e0e361a65f3360e
hovercard-subject-tagissue:1362426119
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/python/cpython/96601/issue_layout
twitter:imagehttps://opengraph.githubassets.com/12d596ab572e927fac02f4203e50630820d2658b6a9ae52efc94279c35ff747d/python/cpython/issues/96601
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/12d596ab572e927fac02f4203e50630820d2658b6a9ae52efc94279c35ff747d/python/cpython/issues/96601
og:image:altProblem Now that 95778 is in, the repr of an int can fail with a ValueError based on its size because repr and str are the same for int thus huge values cannot have a repr. We discussed this while ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegpshead
hostnamegithub.com
expected-hostnamegithub.com
Noneacedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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
release83c08c21cdda978090dc44364b71aa5bc6dcea79
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/96601#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F96601
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F96601
Sign up https://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=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/96601
Reloadhttps://github.com/python/cpython/issues/96601
Reloadhttps://github.com/python/cpython/issues/96601
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/96601
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/96601
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/96601
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/96601
FR: Change int repr on huge values to automatically use hexadecimalhttps://github.com/python/cpython/issues/96601#top
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/gpshead
https://github.com/gpshead
gpsheadhttps://github.com/gpshead
on Sep 5, 2022https://github.com/python/cpython/issues/96601#issue-1362426119
95778https://github.com/python/cpython/issues/95778
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
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.