Ay>mhSrSSKrSSKrSSKrSSKrSSKJr SSKJr SSK J r "SS 5r "S S \ 5r \"S S \ 55r \"SS\ 55r"SS\ 5r"SS\ 5r"SS5r"SS\\R$5r"SS5r"SS\\5r"SS\\5r"SS\\5r"S S!\\R$5r"S"S#5r"S$S%\\5r"S&S'\\5r"S(S)\\5r"S*S+\\R$5r"S,S-\ 5r\"S.S/\55r\"S0S1\55r \"S2S3\\55r!\ RD"S4S5\\R$55r#\$S6:Xa\RJ"5 gg!\a SrGNf=f!\a SrGNf=f)7zB Tests for object finalization semantics, as outlined in PEP 442. N) with_tp_delc$"SS[5nU$)Nc\rSrSrSrSrg)with_tp_del..Cc.[R"S5e)Nzrequires _testcapi.with_tp_delunittestSkipTestclsargskwargss =/opt/alt/python313/lib64/python3.13/test/test_finalization.py__new__with_tp_del..C.__new__s''(HIIN__name__ __module__ __qualname____firstlineno__r__static_attributes__rrrCrs Jrr)objectr rs rrr s J Jr) without_gcc"SS5nU$)Nc\rSrSrSrSrg)without_gc..Cc.[R"S5e)Nzrequires _testcapi.without_gcr r s rrwithout_gc..C.__new__s''(GHHrrNrrrrrr!s Irrrrs rrrs I Ir)supportc\rSrSrSr/r/r/r/rSr Sr \ S5r \ \ RS55rSrSrS rSrg ) NonGCSimpleBasezX The base class for all the objects under test, equipped with various testing features. Frc:URR5 URR5 [RR5 [R "5 UR R5 URR5 gN) survivorsclearerrorsgcgarbagecollect del_calls tp_del_callsr s r_cleanupNonGCSimpleBase._cleanup.s]       rc## [R"5 URR5 URR5 S[ lSv UR(aURSeS[ lUR5 SSS5 g!S[ lUR5 f=f!,(df  g=f7f)z9 A context manager to use around all finalization tests. FNrT) r% disable_gcr1r,r2r' _cleaningr-r4r3s rtestNonGCSimpleBase.test7s    ! MM   !    " " $(-O % ::**Q-'-1) " !-1) " !s5CAC$B#>C C#CC C Ccg)z( Check the object is sane (non-broken). Nrselfs r check_sanityNonGCSimpleBase.check_sanityIrcUR(dEURR[U55 UR 5 UR 5 gg![ a%nURRU5 SnAgSnAff=f)zq PEP 442 finalizer. Record that this was called, check the object is in a sane state, and invoke a side effect. N)r8r1appendidr> side_effect Exceptionr-r=es r__del__NonGCSimpleBase.__del__Nsh  ">>%%bh/!!#  "" " KK  q ! ! "AA B#BBcg)z& A side effect called on destruction. Nrr<s rrDNonGCSimpleBase.side_effect[r@rN)rrrr__doc__r+r1r2r-r8 __slots__ classmethodr4 contextlibcontextmanagerr9r>rHrDrrrrr'r'sj IIL FII!!  " rr'c \rSrSrSrSrSrg) SimpleBaseac$[U5Ulgr*)rCid_r<s r__init__SimpleBase.__init__cs d8rc:UR[U5:Xdegr*)rVrCr<s rr>SimpleBase.check_sanityfsxx2d8###r)rVN)rrrrrWr>rrrrrSrSas $rrSc\rSrSrSrSrg)NonGCjrN)rrrrrNrrrrr\r\jsIrr\c\rSrSrSrSrSrg)NonGCResurrectornrc:URRU5 gz6 Resurrect self by storing self in a class-wide list. Nr+rBr<s rrDNonGCResurrector.side_effectr d#rN)rrrrrNrDrrrrr_r_ns I$rr_c\rSrSrSrg)SimplexrNrrrrrrrrrgrgxrrgc\rSrSrSrSrg)SimpleResurrector|c:URRU5 grbrcr<s rrDSimpleResurrector.side_effect~rerrNrrrrrDrrrrrlrl|s$rrlc>\rSrSrSrSrSrSrSrSr Sr S r g ) TestBasecZ[RSSUl/[RSS&gr*)r.r/ old_garbager<s rsetUpTestBase.setUps::a= 1 rcUR[R/5 U?[R"5 g!U?[R"5 f=fr*) assertEqualr.r/rur0r<s rtearDownTestBase.tearDowns=    RZZ , JJL JJLs :AchUR[[R5[U55 gr*)rysortedrSr1r=idss rassert_del_callsTestBase.assert_del_callss!  4 45vc{CrchUR[[R5[U55 gr*)ryr}rSr2r~s rassert_tp_del_callsTestBase.assert_tp_del_callss!  7 78&+FrcvUR[S[R55[U55 g)Nc38# UHn[U5v M g7fr*rC.0xs r ,TestBase.assert_survivors..sD/C!1/C)ryr}rSr+r~s rassert_survivorsTestBase.assert_survivorss' Dz/C/CDDfSkRrcvUR[S[R55[U55 g)Nc38# UHn[U5v M g7fr*rrs rr*TestBase.assert_garbage..s:z!1zr)ryr}r.r/r~s rassert_garbageTestBase.assert_garbages% :rzz::F3KHrc@[RR5 gr*)rSr+r,r<s rclear_survivorsTestBase.clear_survivorss""$r)ruN) rrrrrvrzrrrrrrrrrrrrrs)DGSI%rrrcl\rSrSrSrSrSr\RS5r \RS5r Sr g) SimpleFinalizationTestz& Test finalization without refcycles. c[R5 [5n[U5/n[R "U5nA[ R"5 URU5 UR/5 URU"5S5 [ R"5 URU5 UR/5 SSS5 g!,(df  g=fr*) rSr9rgrCweakrefrefr.r0rrassertIsr=srwrs r test_simple"SimpleFinalizationTest.test_simples __ Aa5'CQB JJL  ! !# &  ! !" % MM"$ % JJL  ! !# &  ! !" %   B3C Cc[R5 [5n[U5/n[R "U5nA[ R"5 URU5 URU5 URU"5S5 UR5 [ R"5 URU5 UR/5 SSS5 URW"5S5 g!,(df  N&=fr*) rSr9rlrCrrr.r0rr assertIsNotrrrs rtest_simple_resurrect,SimpleFinalizationTest.test_simple_resurrects __ !#Aa5'CQB JJL  ! !# &  ! !# &   RT4 (  " JJL  ! !# &  ! !" % bdD! s CC88 Dc[R5 [5nUR[R "U55 [ U5/nA[R"5 URU5 UR/5 [R"5 URU5 UR/5 SSS5 g!,(df  g=fr*) rSr9r\ assertFalser. is_trackedrCr0rrr=rrs r test_non_gc"SimpleFinalizationTest.test_non_gcs __ A   R]]1- .a5'C JJL  ! !# &  ! !" % JJL  ! !# &  ! !" %  s B+C  Cc[R5 [5nUR[R "U55 [ U5/nA[R"5 URU5 URU5 UR5 [R"5 URUS-5 URU5 SSS5 g!,(df  g=fN) rSr9r_rr.rrCr0rrrrs rtest_non_gc_resurrect,SimpleFinalizationTest.test_non_gc_resurrects __  "A   R]]1- .a5'C JJL  ! !# &  ! !# &  " JJL  ! !#' *  ! !# &  s B>C C*rN) rrrrrMrrr% cpython_onlyrrrrrrrrsE &"   & &  ' 'rrc4^\rSrSrU4SjrU4SjrSrU=r$) SelfCycleBasec.>[TU]5 Xlgr*)superrWrr= __class__s rrWSelfCycleBase.__init__s rcD>[TU]5 URULdegr*)rr>rrs rr>SelfCycleBase.check_sanitys  xx4rr)rrrrrWr>r __classcell__rs@rrrs  rrc\rSrSrSrg)SimpleSelfCyclerNrirrrrrrjrrc\rSrSrSrg)SelfCycleResurrectorrNrirrrrrrjrrc\rSrSrSrSrg)SuicidalSelfCyclecSUlg)' Explicitly break the reference cycle. Nrr<s rrDSuicidalSelfCycle.side_effects rrNrprrrrrsrrc*\rSrSrSrSrSrSrSrg)SelfCycleFinalizationTestzL Test finalization of an object having a single cyclic reference to itself. c[R5 [5n[U5/n[R "U5nA[ R"5 URU5 UR/5 URU"5S5 [ R"5 URU5 UR/5 SSS5 g!,(df  g=fr*) rSr9rrCrrr.r0rrrrs rr%SelfCycleFinalizationTest.test_simples __ !Aa5'CQB JJL  ! !# &  ! !" % MM"$ % JJL  ! !# &  ! !" %  rc[R5 [5n[U5/n[R "U5nA[ R"5 URU5 URU5 URU"5S5 UR5 [ R"5 URU5 UR/5 URU"5S5 SSS5 g!,(df  g=fr*) rSr9rrCrrr.r0rrrrrs rr/SelfCycleFinalizationTest.test_simple_resurrects __ $&Aa5'CQB JJL  ! !# &  ! !# & MM"$ %  " JJL  ! !# &  ! !" % MM"$ %!  s CC88 Dc[R5 [5n[U5/n[R "U5nA[ R"5 URU5 UR/5 URU"5S5 [ R"5 URU5 UR/5 URU"5S5 SSS5 g!,(df  g=fr*) rSr9rrCrrr.r0rrrrs rtest_simple_suicide-SelfCycleFinalizationTest.test_simple_suicide%s__ !#Aa5'CQB JJL  ! !# &  ! !" % MM"$ % JJL  ! !# &  ! !" % MM"$ %  s C C(( C6rN) rrrrrMrrrrrrrrrs &&(&rrc.^\rSrSrSrU4SjrSrU=r$) ChainedBasei7c*SUlXlXlg)NFsuicidedleftright)r=rs rchainChainedBase.chain9s   rcz>[TU]5 UR(aURbeURbegURnUR(aURbeOURULdeURnUR(aURbegURULdegr*)rr>rrr)r=rrrs rr>ChainedBase.check_sanity>s  ==99$ $$::% %%99D}}zz)))zzT)))JJE~~zz)))zzT)))r)rr)rrrrrr>rrrs@rrr7s **rrc\rSrSrSrg) SimpleChainediOrNrirrrrrOrjrrc\rSrSrSrg)ChainedResurrectoriRrNrirrrrrRrjrrc\rSrSrSrSrg)SuicidalChainediUc.SUlSUlSUlg)rTNrr<s rrDSuicidalChained.side_effectWs   r)rrrNrprrrrrUsrrcZ\rSrSrSrSrSrSrSrSr Sr S r S r S r S rS rSrg)CycleChainFinalizationTesti`z Test finalization of a cyclic chain. These tests are similar in spirit to the self-cycle tests above, but the collectable object graph isn't trivial anymore. cUVs/sH o""5PM nn[[U55HnX4RX4S- 5 M U$s snf)N)rangelenr)r=classesr nodesis r build_chain&CycleChainFinalizationTest.build_chaingsI")*'3'*s5z"A HNN51: &# +sA cJ[U5n[R5 URU5nUVs/sHn[ U5PM nnUVs/sHn[ R "U5PM nnA[R"5 URU5 UR/5 URUVs/sH ow"5PM snS/U-5 [R"5 URU5 SSS5 gs snfs snfs snf!,(df  g=fr*) rrSr9rrCrrr.r0rrry)r=rNrrrwrsrs rcheck_non_resurrecting_chain7CycleChainFinalizationTest.check_non_resurrecting_chainms L __ $$W-E"'(%Q2a5%C(+015a7;;q>5C1 JJL  ! !# &  ! !" %   S1SrbdS1D6A: > JJL  ! !# & (1 2 s5DD D D 1A D:D 2DD D"c[U5n[R5 URU5n[U5nUVs/sHn[ U5PM nnUVs/sH%n[ U[ 5(dM[ U5PM' nnUVs/sHn[R"U5PM nnA[R"5 URU5 URU5 URUVs/sH o"5PM snS/U-5 UR5 [R"5 URU5 UR/5 SSS5 gs snfs snfs snfs snf!,(df  g=fr*)rrSr9rrC isinstancerlrrr.r0rrryr) r=rrrrr survivor_idsrrs rcheck_resurrecting_chain3CycleChainFinalizationTest.check_resurrecting_chain{s' L __ $$W-EE A"'(%Q2a5%C(+0U5aJqBS4TEBqE5LU+015a7;;q>5C1 JJL  ! !# &  ! !, /   S1SrbdS1D6A: >  " JJL  ! !# &  ! !" % )U1 2 sI!E7E#E7E(9E(E7 E-.A E77E2 AE7#E77 Fc6UR[/S-5 gN)rrr<s rtest_homogenous*CycleChainFinalizationTest.test_homogenouss ))=/A*=>rc6UR[/S-5 gr)rrr<s rtest_homogenous_resurrect4CycleChainFinalizationTest.test_homogenous_resurrects %%'9&:Q&>?rc6UR[/S-5 gr)rrr<s rtest_homogenous_suicidal3CycleChainFinalizationTest.test_homogenous_suicidals ))?*;a*?@rc@UR[[/S-5 grrrrr<s rtest_heterogenous_suicidal_one9CycleChainFinalizationTest.test_heterogenous_suicidal_ones ))?M*JQ*NOrcLUR[/S-[/S--5 grr r<s rtest_heterogenous_suicidal_two9CycleChainFinalizationTest.test_heterogenous_suicidal_twos' ))   !]Oa$7 7 9rc@UR[[/S-5 gr)rrrr<s rtest_heterogenous_resurrect_one:CycleChainFinalizationTest.test_heterogenous_resurrect_ones %%'9=&IA&MNrcJUR[[[/S-5 grrrrrr<s rtest_heterogenous_resurrect_two:CycleChainFinalizationTest.test_heterogenous_resurrect_twos  %%  @1 D FrcbUR[/S-[/S--[/S--5 grrr<s r!test_heterogenous_resurrect_threerEr-rFs rrHLegacyBase.__del__s^ ">>%%bh/!!#" " KK  q ! ! "sAA A8A33A8cUR(dEURR[U55 UR 5 UR 5 gg![ a%nURRU5 SnAgSnAff=f)z: Legacy (pre-PEP 442) finalizer, mapped to a tp_del slot. N)r8r2rBrCr>rDrEr-rFs r __tp_del__LegacyBase.__tp_del__sj ">>!!((D2!!#  "" " KK  q ! ! "rJrN)rrrrrHr!rrrrrrs " "rrc\rSrSrSrg)LegacyirNrirrrr$r$rr$c\rSrSrSrSrg)LegacyResurrectoric:URRU5 grbrcr<s rrDLegacyResurrector.side_effectrerrNrprrrr'r's$rr'c\rSrSrSrg)LegacySelfCycleirNrirrrr+r+r%rr+c>^\rSrSrSrU4SjrSrSrSrSr U=r $)LegacyFinalizationTestiz- Test finalization of objects with a tp_del. c>[RR5 [R"5 [TU]5 gr*)r.r/r,r0rrzrs rrzLegacyFinalizationTest.tearDowns)   rc[R5 [5n[U5/n[R "U5nA[ R"5 URU5 URU5 UR/5 URU"5S5 [ R"5 URU5 URU5 SSS5 g!,(df  g=fr*) rSr9r$rCrrr.r0rrrrrs r test_legacy"LegacyFinalizationTest.test_legacys __ Aa5'CQB JJL  ! !# &  $ $S )  ! !" % MM"$ % JJL  ! !# &  $ $S )  s CC"" C0c\[R5 [5n[U5/n[R "U5nA[ R"5 URU5 URU5 URU5 URU"5S5 UR5 [ R"5 URU5 URUS-5 URU5 SSS5 URW"5S5 g!,(df  N&=fr) rSr9r'rCrrr.r0rrrrrrs rtest_legacy_resurrect,LegacyFinalizationTest.test_legacy_resurrects __ !#Aa5'CQB JJL  ! !# &  $ $S )  ! !# & MM"$ %  " JJL  ! !# &  $ $S1W -  ! !# & bdD!! s C(D D+c[R5 [5n[U5/n[R "U5nA[ R"5 UR/5 UR/5 UR/5 URU5 URU"5S5 S[ RSlSSS5 UR/5 URW"5S5 g!,(df  N7=f)Nr)rSr9r+rCrrr.r0rrrrrr/rrs rtest_legacy_self_cycle-LegacyFinalizationTest.test_legacy_self_cycles __ !Aa5'CQB JJL  ! !" %  $ $R (  ! !" %    $   RT4 ( $BJJqM  B bdD! s B6C<< D r) rrrrrMrzr1r4r7rrrs@rr-r-s! *"&""rr-__main__)&rMrPr.r r _testcapir ImportErrorrr9r%r'rSr\r_rgrlrrTestCaserrrrrrrrrrrrr$r'r+rr-rmainrrrr>s %$? ? D$$ O  $$ $ Z $ $%%<>'Xx'8'8>'B   mV  =*;  v7&(*;*;7&t**0 K  &7 k6GT8+<+<GTZ""0  Z    $ $ $  mZ    >"Xx'8'8>">"B z MMO[s"FF$ F! F!$ F10F1