Title: Creation of an internal decimal context for `_pylong` has side effects on `decimal` · Issue #123284 · python/cpython · GitHub
Open Graph Title: Creation of an internal decimal context for `_pylong` has side effects on `decimal` · Issue #123284 · python/cpython
X Title: Creation of an internal decimal context for `_pylong` has side effects on `decimal` · Issue #123284 · python/cpython
Description: Bug report Bug description: The _decimal module was recently fixed in #123243. I also found that _pylong leaks globals due to the creation of a global context to use as a local context: _unbounded_dec_context = decimal.getcontext().copy(...
Open Graph Description: Bug report Bug description: The _decimal module was recently fixed in #123243. I also found that _pylong leaks globals due to the creation of a global context to use as a local context: _unbounded_...
X Description: Bug report Bug description: The _decimal module was recently fixed in #123243. I also found that _pylong leaks globals due to the creation of a global context to use as a local context: _unbounded_...
Opengraph URL: https://github.com/python/cpython/issues/123284
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Creation of an internal decimal context for `_pylong` has side effects on `decimal`","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nThe `_decimal` module was recently fixed in #123243. I also found that `_pylong` leaks globals due to the creation of a global context to use as a local context:\r\n\r\n```py\r\n_unbounded_dec_context = decimal.getcontext().copy()\r\n_unbounded_dec_context.prec = decimal.MAX_PREC\r\n_unbounded_dec_context.Emax = decimal.MAX_EMAX\r\n_unbounded_dec_context.Emin = decimal.MIN_EMIN\r\n_unbounded_dec_context.traps[decimal.Inexact] = 1 # sanity check\r\n```\r\n\r\nThis context is used as `with decimal.localcontext(_unbounded_dec_context)`. On the other hand `decimal.getcontext().copy()` returns a *copy* of the decimal context for the current thread (or set it to `decimal.DefaultContext` if none exists). Instead of setting it like that, I suggest that we construct a `decimal.Context()` object directly in `_pylong` instead of possibly polluting the `decimal` module (whether it's the C or the python implementation).\r\n\r\n\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nLinux\r\n\r\n\u003c!-- gh-linked-prs -->\r\n### Linked PRs\r\n* gh-123285\r\n\u003c!-- /gh-linked-prs -->\r\n","author":{"url":"https://github.com/picnixz","@type":"Person","name":"picnixz"},"datePublished":"2024-08-24T11:24:25Z","url":"https://github.com/python/cpython/issues/123284"}
| 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:f2c6521c-a983-e2ce-9493-f270d6a7f610 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6EE:5F360:1AABDE1:231E01E:6B067CBC |
| html-safe-nonce | 4f3e761c0b4bc22fc81af1e0b843da5926d939d2f03ff6bdfb1d2ead2d42fcdc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkVFOjVGMzYwOjFBQUJERTE6MjMxRTAxRTo2QjA2N0NCQyIsInZpc2l0b3JfaWQiOiI0Mjc1NjIwMjM1MzU4NjY1OTE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 755b00d1acec2505a58aa677b1e30023d0aca6e0b09d151104b2dfdcfff23fe8 |
| hovercard-subject-tag | issue:2484518255 |
| 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/python/cpython/123284/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ce4aec8b9cbbb37c2e83809b07f34dfa67eb87822a328ac8ae72ce02de7b703e/python/cpython/issues/123284 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ce4aec8b9cbbb37c2e83809b07f34dfa67eb87822a328ac8ae72ce02de7b703e/python/cpython/issues/123284 |
| og:image:alt | Bug report Bug description: The _decimal module was recently fixed in #123243. I also found that _pylong leaks globals due to the creation of a global context to use as a local context: _unbounded_... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | picnixz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4462ff7ebfd3d551f202659f2423dae617b6849d23b1df6465dc504ef497d14a |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 6d3909414814ff86ce7da4c51a0f4918a13fb41b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width