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

Merged
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
4d648b4
Add tests
fxeqxmulfxJun 22, 2025
77e9ca7
Organize tests
sergey-miryanovJun 22, 2025
b6825da
Simplify tests
sergey-miryanovJun 24, 2025
f62d43e
Remove extra line
sergey-miryanovJul 4, 2025
398c4f5
Add extra comments
sergey-miryanovJul 4, 2025
7dd9669
Add tests for checking that weakrefs clears before and after finaliza…
sergey-miryanovJul 4, 2025
1da73b3
Make tests a little bit reliable
sergey-miryanovJul 5, 2025
0510539
Simplify tests
sergey-miryanovJul 5, 2025
50410d6
Use unittest asserts
sergey-miryanovJul 6, 2025
aa18e74
Move test_clearing_weakrefs_in_gc to test_weakref
sergey-miryanovJul 8, 2025
7788e55
Apply suggestions from code review
sergey-miryanovJul 8, 2025
d125d06
Merge branch 'main' into gh-135552-add-tests-gc-weakref-tp_subclasses
naschemeAug 7, 2025
0339d54
Revise test_clearing_weakrefs_in_gc test
naschemeAug 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
Revise test_clearing_weakrefs_in_gc test
Types are not treated specially, it only matters if the weakref has a callback or not.
  • Loading branch information
@nascheme
nascheme authoredAug 7, 2025
commit0339d544908326dfb5a9c0c3bb138f40b654c65f
16 changes: 5 additions & 11 deletionsLib/test/test_weakref.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1045,30 +1045,24 @@ def callback(obj):
self.assertNotRegex(stderr, "_Py_Dealloc: Deallocator of type 'TestObj'")

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
# This test checks that when finalizers are called:
# 1. weakrefs with callbacks have been cleared
# 2. weakrefs without callbacks have not been cleared
errors = []
def test():
class Class:
def __init__(self):
self._self = self
self.wr1 = weakref.ref(Class, lambda x: None)
self.wr2 = weakref.ref(Class)
self.wr3 = weakref.ref(self)

def __del__(self):
# we can't use assert* here, because gc will swallow
# exceptions
if self.wr1() is not None:
errors.append("Typeweakref with callbackis not None")
errors.append("weakref with callbackas cleared")
if self.wr2() is not Class:
errors.append("Type weakref is not Class")
if self.wr3() is not None:
errors.append("Instance weakref is not None")
errors.append("weakref without callback was cleared")

Class()

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp