FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `_random.Random` by picnixz · Pull Request #138341 · python/cpython · GitHub

/ cpython Public

gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to _random.Random - #138341

Merged
picnixz merged 3 commits into
python:mainfrom
picnixz:fix/gc/random-heap-types-116946
Sep 3, 2025
Merged

gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to _random.Random#138341
picnixz merged 3 commits into
python:mainfrom
picnixz:fix/gc/random-heap-types-116946

Conversation

picnixz commented Sep 1, 2025
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

On main the following leaks:

$ ./python -X showrefcount -c 'import _random; s = _random.Random(); t = type(s); t._random = s'
[42 refs, 26 blocks]

ZeroIntensity previously approved these changes Sep 1, 2025

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM with one idea.

Comment thread Modules/_randommodule.c Outdated

Copy link
Copy Markdown
Member

Wait, why is _random.Random mutable?

Copy link
Copy Markdown
Member

Probably because it would break code to change that.

Copy link
Copy Markdown
Member

It became mutable in 3.9. I think this is a bug.

picnixz commented Sep 1, 2025

Copy link
Copy Markdown
Member Author

It became mutable in 3.9. I think this is a bug.

I was also surprised but I just didn't want to break stuff here.

Copy link
Copy Markdown
Contributor

It became mutable in 3.9. I think this is a bug.

Yes, I think adding IMMUTABLE flag was missed while conversion, it shouldn't be a mutable type.

Copy link
Copy Markdown
Contributor

See #88074 where most of the converted types where made immutable, same should be done for random and epoll

Comment thread Modules/_randommodule.c Outdated
picnixz marked this pull request as draft September 1, 2025 18:57
picnixz changed the title gh-116946: fully implement GC protocol for random.Random gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to _random.Random Sep 2, 2025

picnixz commented Sep 2, 2025

Copy link
Copy Markdown
Member Author

@rhettinger Does this change satisfy you? do you want this to be backported?

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

vstinner commented Sep 2, 2025

Copy link
Copy Markdown
Member

do you want this to be backported?

Please don't backport this change. It would be surprising that a class becomes immutable in 3.x.y bugfix release.

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, but I would prefer a single large PR that fixes the 3.9 error by making all converted types immutable.

picnixz merged commit 51244ba into python:main Sep 3, 2025
54 of 63 checks passed
picnixz deleted the fix/gc/random-heap-types-116946 branch September 3, 2025 07:55
lkollar pushed a commit to lkollar/cpython that referenced this pull request Sep 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL