You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Docs: the Reference says integer literals have no length limit, but some long decimal literals fail to compile #162602
The Reference (https://docs.python.org/dev/reference/lexical_analysis.html#integers) says "There is no limit for the length of integer literals apart from what can be stored in available memory". With the default integer string conversion limit (gh-95778), the 4301-digit decimal literal below doesn't compile, while the longer hexadecimal literal does:
4300 characters: compiles
4301 characters: SyntaxError: Exceeds the limit (4300 digits) for integer string conversion
5002 characters: compiles
The limit's section says such source "will encounter an error during parsing"; the Reference could say so and link there. I found it while writing a Lean spec of Python.
Thank you for taking the time to open this issue. Python is a community-driven project, and we want it to be a welcoming place to learn and collaborate.
This issue appears to have been written with AI assistance. Please explain your issue in your own words and describe how you checked the information you provided. This helps us understand your issue and leaves more time to address other issues.
CPython has a global limit for converting between int and str to mitigate denial of service attacks. This limit only applies to decimal or other non-power-of-two number bases. Hexadecimal, octal, and binary conversions are unlimited. The limit can be configured.
In this wording the feature might look as CPython-specific. Though, both PyPy and GraalPy implement same API, with same defaults.
Maybe it should be optional for alternative implementations? With a better bigint library than we have in the CPython internals, say with the GNU GMP - this limitation is not helpful.
I would have expected that the conversion int<->str has limits as we currently do but hardcoding a literal should not cause any parsing issue (where is the string in my code except that the code itself is parsed as a string).
That being said, I don't know how we can improve the docs without saying "well the specs say that but CPython and many other implementations do differently for practical reasons, use hexadecimal strings if you need to encode very large integers". I think this doesn't ring well.
@skirpichev ~10 issues in different CPython domains were created by @Robertboy18 (first time contributor) in a batch.
That's why I've added the label.
If all issues are valuable -- I have no objections. But please review them carefully.
@asvetlov@picnixz sorry for the batch! These all came out of a Lean formalization of the language reference I'm working on, and it has been batching them up. I'll review each one more carefully and slow it down from here. Thanks for looking at them, I just wanted to help get these fixed fast :)
This won't likely happena s they are not critical bugs. While maybe trivial to fix by rewording, we have too many PRs to review before we address those (which I believe are rather all low-priority).
~10 issues in different CPython domains were created
Ah, just for a bulk creation. But was any concrete issue unclear or misleading?
I would have expected that the conversion int<->str has limits as we currently do but hardcoding a literal should not cause any parsing issue (where is the string in my code except that the code itself is parsed as a string).
So, do you think we can relax limitation here? It's coming from using PyLong_FromString() in Parser/ and looks to be intentional (reflected in docs, in "Caution" mark). But maybe it was here just to simplify the patch...
I don't see how this constraint helps for security in case of parsing source code. But see that it can complicate docs for no good reason.
@skirpichev don't get me wrong. I didn't say that this batch had misleading or malformed issues.
My point is closer to what @picnixz wrote.
We, as Python core developers with commit rights, are responsible for responding to issues and merging pull requests. We should read proposed changes carefully with our own eyes before reacting.
Automated issues and PRs are very common nowadays, and they are a red flag for me. The proposal may be worthwhile, but a machine can generate these faster than I can analyze them. Each one usually needs review and comments, and eventually acceptance or rejection.
The strategy that works for outside contributors is called "communication", especially for a first issue. Pick a target, work on it, and talk with the reviewers. Once it's merged, you know a few core devs who will probably help with your next review, and so on.
Filing 10 issues at once as a newcomer nobody knows yet is a genuine anti-pattern to me.
Again, please don't get me wrong. I use Claude Code on my daily basis, but I always check its output by my own eyes before posting it to public domain.
If I review 10 different AI bug reports generated by my local machine -- I spend some time on each before pressing "send" button. That was my source of frustration.
Well, I'm not and may ask dumb questions, do silly thing and even invade Poland! :)
Automated issues and PRs are very common nowadays, and they are a red flag for me. The proposal may be worthwhile, but a machine can generate these faster than I can analyze them.
That's a valid concern, but I would like to be interpreting CPython AI guidelines correctly. Rule one:
Use the AI policy labels for issues and PRs that don’t follow the guidelines for using AI tools. Don’t apply them only because AI tools were used, or because the author disclosed using them.
Activity
bedevere-app commentedon Nov 25, 2026
Thank you for taking the time to open this issue. Python is a community-driven project, and we want it to be a welcoming place to learn and collaborate.
This issue appears to have been written with AI assistance. Please explain your issue in your own words and describe how you checked the information you provided. This helps us understand your issue and leaves more time to address other issues.
Please read our guidelines for using AI tools.
skirpichev commentedon Nov 25, 2026
Not sure that I understand reasons for AI-related tag. Issue looks clear and well written.
The problem I see is that the language reference is for the Python language, not just CPython. While Integer string conversion length limitation says:
In this wording the feature might look as CPython-specific. Though, both PyPy and GraalPy implement same API, with same defaults.
Maybe it should be optional for alternative implementations? With a better bigint library than we have in the CPython internals, say with the GNU GMP - this limitation is not helpful.
picnixz commentedon Nov 25, 2026
I would have expected that the conversion int<->str has limits as we currently do but hardcoding a literal should not cause any parsing issue (where is the string in my code except that the code itself is parsed as a string).
That being said, I don't know how we can improve the docs without saying "well the specs say that but CPython and many other implementations do differently for practical reasons, use hexadecimal strings if you need to encode very large integers". I think this doesn't ring well.
asvetlov commentedon Nov 25, 2026
@skirpichev ~10 issues in different CPython domains were created by @Robertboy18 (first time contributor) in a batch.
That's why I've added the label.
If all issues are valuable -- I have no objections. But please review them carefully.
Robertboy18 commentedon Nov 25, 2026
@asvetlov @picnixz sorry for the batch! These all came out of a Lean formalization of the language reference I'm working on, and it has been batching them up. I'll review each one more carefully and slow it down from here. Thanks for looking at them, I just wanted to help get these fixed fast :)
picnixz commentedon Nov 25, 2026
This won't likely happena s they are not critical bugs. While maybe trivial to fix by rewording, we have too many PRs to review before we address those (which I believe are rather all low-priority).
skirpichev commentedon Nov 25, 2026
Ah, just for a bulk creation. But was any concrete issue unclear or misleading?
So, do you think we can relax limitation here? It's coming from using PyLong_FromString() in Parser/ and looks to be intentional (reflected in docs, in "Caution" mark). But maybe it was here just to simplify the patch...
I don't see how this constraint helps for security in case of parsing source code. But see that it can complicate docs for no good reason.
asvetlov commentedon Nov 25, 2026
@skirpichev don't get me wrong. I didn't say that this batch had misleading or malformed issues.
My point is closer to what @picnixz wrote.
We, as Python core developers with commit rights, are responsible for responding to issues and merging pull requests. We should read proposed changes carefully with our own eyes before reacting.
Automated issues and PRs are very common nowadays, and they are a red flag for me. The proposal may be worthwhile, but a machine can generate these faster than I can analyze them. Each one usually needs review and comments, and eventually acceptance or rejection.
The strategy that works for outside contributors is called "communication", especially for a first issue. Pick a target, work on it, and talk with the reviewers. Once it's merged, you know a few core devs who will probably help with your next review, and so on.
Filing 10 issues at once as a newcomer nobody knows yet is a genuine anti-pattern to me.
Again, please don't get me wrong. I use Claude Code on my daily basis, but I always check its output by my own eyes before posting it to public domain.
If I review 10 different AI bug reports generated by my local machine -- I spend some time on each before pressing "send" button. That was my source of frustration.
skirpichev commentedon Nov 25, 2026
Well, I'm not and may ask dumb questions, do silly thing and even invade Poland! :)
That's a valid concern, but I would like to be interpreting CPython AI guidelines correctly. Rule one:
Rule two:
My interpretation: