-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-118164: str(10**10000) hangs if the C _decimal module is missing #118503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I came to the same solution. The simple test can be based on the #118027 example. But the case of |
EDIT: never mind. I still don't understand how I don't know anything about how to write tests for @rhettinger, is this shallow to you? I need help to get started. I'd like to add a test that sets the context |
No idea. |
A smidgen of progress: in the first block that tests whether |
And another smidgen: in the other block, |
After the comment here: # if m > p*100//_log10_lb(xc) then m > p/log10(xc), hence xc**m >
# 10**p and the result is not representable.
if xc > 1 and m > p*100//_log10_lb(xc):
return None I inserted: assert xc != 1, self
assert not _is_power_of_10(str(xc)), self The second assert is more general. No code I have triggers them (including test_decimal), and I haven't been able to contrive inputs that trigger them. So I've so far failed to falsify my original guess that, near the end of this code, Yet the code guards against If so, doesn't mean there's a bug, just that the code is being a tiny bit more cautious than necessary. For example, perhaps this code was written before the much earlier code in the function that special-cases the snot out of inputs where Also if so, |
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Serhiy and I independently concluded that exact powers of 10 aren't possible in these contexts, so just checking the string length is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @tim-one for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…sing (pythonGH-118503) * Initial stab. * Test the tentative fix. Hangs "forever" without this change. * Move the new test to a better spot. * New comment to explain why _convert_to_str allows any poewr of 10. * Fixed a comment, and fleshed out an existing test that appeared unfinished. * Added temporary asserts. Or maybe permanent ;-) * Update Lib/_pydecimal.py Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> * Remove the new _convert_to_str(). Serhiy and I independently concluded that exact powers of 10 aren't possible in these contexts, so just checking the string length is sufficient. * At least for now, add the asserts to the other block too. * 📜🤖 Added by blurb_it. --------- (cherry picked from commit 999f0c5) Co-authored-by: Tim Peters <tim.peters@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
GH-118584 is a backport of this pull request to the 3.12 branch. |
I think that this was a bug, and this change should be backported. |
@serhiy-storchaka, backporting is a fine idea. I'll leave it to you 😄. |
…ssing (GH-118503) (GH-118584) Serhiy and I independently concluded that exact powers of 10 aren't possible in these contexts, so just checking the string length is sufficient. (cherry picked from commit 999f0c5) Co-authored-by: Tim Peters <tim.peters@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…sing (python#118503) * Initial stab. * Test the tentative fix. Hangs "forever" without this change. * Move the new test to a better spot. * New comment to explain why _convert_to_str allows any poewr of 10. * Fixed a comment, and fleshed out an existing test that appeared unfinished. * Added temporary asserts. Or maybe permanent ;-) * Update Lib/_pydecimal.py Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> * Remove the new _convert_to_str(). Serhiy and I independently concluded that exact powers of 10 aren't possible in these contexts, so just checking the string length is sufficient. * At least for now, add the asserts to the other block too. * 📜🤖 Added by blurb_it. --------- Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This is somewhat of a conceptual mess, related to two issues:
#118164
#118027
These only occur if the C
decimal
module isn't available, so_pydecimal.py
is used instead. But CPython doesn't use_pydecimal.py
for anything anymore, so this can only happen in a damaged CPython installation.. Or, significantly, under PyPy, which hasn't incorporated the Clibmpdec
CPython uses to implementdecimal
.Confounding it is that the first issue above can't be tested even after this PR's changes. This PR repairs the proximate cause of the failure, which causes it to fail instead later. That failure is the subject of a different PR:
#118483
If someone can think of a sane way to test this, I'd be grateful 😄l.
_decimal
module is missing #118164