Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-135552: Add tests that check if weakref for tp_subclasses cleared after finalization#136304

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@sergey-miryanov
Copy link
Contributor

@sergey-miryanovsergey-miryanov commentedJul 4, 2025
edited by bedevere-appbot
Loading

@sergey-miryanov
Copy link
ContributorAuthor

I believe this PR should skip news

@nascheme
Copy link
Member

This looks okay to me. Some suggested improvements. The new test might fit better intotest_weakref.py but that's minor.

I don't think it's required to run these in a separate Python process. That makes the test run slower and it's not supposed to crash. Generally a separate process is used for the tests that exercise the interpreter shutdown logic and we are not testing that. So you could just do:

    def test_clearing_weakrefs_in_gc(self):        # This test checks that:        # 1. weakrefs for types with callbacks are cleared before the        # finalizer is called        # 2. weakrefs for types without callbacks are cleared after the        # finalizer is called        # 3. other weakrefs cleared before the finalizer is called        errors = []        class Class:            def __init__(self):                self._self = self                self._1 = weakref.ref(Class, lambda x: None)                self._2 = weakref.ref(Class)                self._3 = weakref.ref(self)            def __del__(self):                if self._1() is not None:                    errors.append("Type weakref with callback is not None as expected")                if self._2() is not Class:                    errors.append("Type weakref is not Class as expected")                if self._3() is not None:                    errors.append("Instance weakref is not None as expected")        Class()        gc.collect()        self.assertEqual(errors, [])

I find the variable naming a bit esoteric. I would have just called themwr1,wr2 andwr3.

sergey-miryanov reacted with thumbs up emoji

@sergey-miryanov
Copy link
ContributorAuthor

@nascheme Thanks for review! Fixed.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@sergey-miryanov
Copy link
ContributorAuthor

@kumaraditya303 Thanks for review!

Types are not treated specially, it only matters if the weakref has a callback or not.
@naschemenascheme merged commit25518f5 intopython:mainAug 8, 2025
40 checks passed
@sergey-miryanov
Copy link
ContributorAuthor

Thanks everyone!

efimov-mikhail reacted with thumbs up emoji

@sergey-miryanovsergey-miryanov deleted the gh-135552-add-tests-gc-weakref-tp_subclasses branchAugust 8, 2025 04:42
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull requestAug 19, 2025
These are tests to ensure behaviour introduced bypythonGH-136189 is working as expected.Co-authored-by: Mikhail Borisov <43937008+fxeqxmulfx@users.noreply.github.com>Co-authored-by: Kumar Aditya <kumaraditya@python.org>Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kumaraditya303kumaraditya303kumaraditya303 left review comments

+1 more reviewer

@neoneneneoneneneonene left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

skip newstestsTests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@sergey-miryanov@nascheme@neonene@kumaraditya303@StanFromIreland@fxeqxmulfx

[8]ページ先頭

©2009-2025 Movatter.jp