ó {G_Tc@sjddlZddlmZmZmZmZdejfd„ƒYZd„Ze dkrfeƒndS(iÿÿÿÿN(tcheck_syntax_errortcheck_py3k_warningstcheck_warningst run_unittestt ScopeTestscBseZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(cCsQd„}|dƒ}|dƒ}|j|dƒdƒ|j|dƒdƒdS(Ncs‡fd†}|S(Ncsˆ|S(N((ty(tx(s+/usr/local/lib/python2.7/test/test_scope.pytadder s((RR((Rs+/usr/local/lib/python2.7/test/test_scope.pyt make_adder sii iiþÿÿÿi(t assertEqual(tselfRtinctplus10((s+/usr/local/lib/python2.7/test/test_scope.pyttestSimpleNestings    cCsQd„}|dƒ}|dƒ}|j|dƒdƒ|j|dƒdƒdS(Ncs‡fd†}|ƒS(Ncs‡fd†}|S(Ncsˆ|S(N((R(R(s+/usr/local/lib/python2.7/test/test_scope.pyRs((R(R(s+/usr/local/lib/python2.7/test/test_scope.pytextras((RR((Rs+/usr/local/lib/python2.7/test/test_scope.pyt make_adder2sii iiþÿÿÿi(R (R RR R ((s+/usr/local/lib/python2.7/test/test_scope.pyttestExtraNestings    cCsQd„}|dƒ}|dƒ}|j|dƒdƒ|j|dƒdƒdS(Ncs‡fd†}ˆd‰|S(Ncsˆ|S(N((R(R(s+/usr/local/lib/python2.7/test/test_scope.pyR'si((RR((Rs+/usr/local/lib/python2.7/test/test_scope.pyt make_adder3&s ii iiiþÿÿÿi(R (R RR R ((s+/usr/local/lib/python2.7/test/test_scope.pyttestSimpleAndRebinding$s    csT‡fd†}d‰|ƒ}|j|dƒdƒd‰|j|dƒdƒdS(Ncs‡fd†}|ƒS(Ncs‡fd†}|ƒS(Ncs‡fd†}|S(Ncsˆ|S(N((R(tglobal_x(s+/usr/local/lib/python2.7/test/test_scope.pyR7s((R(R(s+/usr/local/lib/python2.7/test/test_scope.pytnest6s((R(R(s+/usr/local/lib/python2.7/test/test_scope.pyR5s((R(R(s+/usr/local/lib/python2.7/test/test_scope.pyt make_adder44siii iþÿÿÿi(R (R RR((Rs+/usr/local/lib/python2.7/test/test_scope.pyttestNestingGlobalNoFree2s   cCsQd„}|dƒ}|dƒ}|j|dƒdƒ|j|dƒdƒdS(Ncs dd‡fd†ƒY}|ƒS(NtAddercseZ‡fd†ZRS(csˆ|S(N((R R(R(s+/usr/local/lib/python2.7/test/test_scope.pyt__call__Hs(t__name__t __module__R((R(s+/usr/local/lib/python2.7/test/test_scope.pyRGs(((RR((Rs+/usr/local/lib/python2.7/test/test_scope.pyt make_adder5Fsii iiþÿÿÿi(R (R RR R ((s+/usr/local/lib/python2.7/test/test_scope.pyttestNestingThroughClassDs    cCsQd„}|dƒ}|dƒ}|j|dƒdƒ|j|dƒdƒdS(NcSsd„}|a|S(NcSst|S(N(t global_nest_x(R((s+/usr/local/lib/python2.7/test/test_scope.pyRVs(R(RR((s+/usr/local/lib/python2.7/test/test_scope.pyt make_adder6Ts ii i iþÿÿÿi(R (R RR R ((s+/usr/local/lib/python2.7/test/test_scope.pyttestNestingPlusFreeRefToGlobalRs    cCs/d„}|dƒ}|j|dƒdƒdS(NcSsd„}|dƒS(Ncsd‰‡fd†}|S(Ni*csˆ|S(N((tz(R(s+/usr/local/lib/python2.7/test/test_scope.pythfs((RR!((Rs+/usr/local/lib/python2.7/test/test_scope.pytgdsi((RR"((s+/usr/local/lib/python2.7/test/test_scope.pytfcs i ii/(R (R R#t test_func((s+/usr/local/lib/python2.7/test/test_scope.pyttestNearestEnclosingScopeas  csSd„‰‡fd†}|dddƒ}|dddƒ}|j|ƒdƒdS( NcSs|S(N((R((s+/usr/local/lib/python2.7/test/test_scope.pytidentitypscs‡‡‡fd†}|S(Ncs0|ˆ}‡‡‡‡fd†}|ˆ‰|S(NcsˆˆˆˆƒS(N(((tbR&RR (s+/usr/local/lib/python2.7/test/test_scope.pyR!vs((taR'tcR!(R&RR (R'Rs+/usr/local/lib/python2.7/test/test_scope.pyR"ts  ((RRR R"(R&(RR s+/usr/local/lib/python2.7/test/test_scope.pyR#ssiiiiii'(R (R R#R"R!((R&s+/usr/local/lib/python2.7/test/test_scope.pyttestMixedFreevarsAndCellvarsns   csÂd„}|ƒ}|j|jƒdƒ|j|jƒdƒ|j|jƒdƒd‰dd‡fd†ƒY}|ƒ}|j|jƒdƒ|j|jƒdƒ|j|jƒdƒdS(Ncs&d‰dd‡fd†ƒY}|ƒS(NtvartTestcs2eZd„Z‡fd†Zd„Zd„ZRS(cSsdS(Ntmethod((R ((s+/usr/local/lib/python2.7/test/test_scope.pytmethod_and_var‡scsˆS(N((R (R.(s+/usr/local/lib/python2.7/test/test_scope.pyttest‰scSs tdƒS(Ntglobal(tstr(R ((s+/usr/local/lib/python2.7/test/test_scope.pyt actual_global‹scSs t|ƒS(N(R1(R ((s+/usr/local/lib/python2.7/test/test_scope.pyR1s(RRR.R/R2R1((R.(s+/usr/local/lib/python2.7/test/test_scope.pyR,†s  (((R,((R.s+/usr/local/lib/python2.7/test/test_scope.pyR/„s R+R-R0R,cs2eZd„Z‡fd†Zd„Zd„ZRS(cSsdS(NR-((R ((s+/usr/local/lib/python2.7/test/test_scope.pyR.™scsˆS(N((R (R.(s+/usr/local/lib/python2.7/test/test_scope.pyR/›scSs tdƒS(NR0(R1(R ((s+/usr/local/lib/python2.7/test/test_scope.pyR2scSs t|ƒS(N(R1(R ((s+/usr/local/lib/python2.7/test/test_scope.pyR1Ÿs(RRR.R/R2R1((R.(s+/usr/local/lib/python2.7/test/test_scope.pyR,—s  ((R R/R.R2(R R/ttR,((R.s+/usr/local/lib/python2.7/test/test_scope.pyttestFreeVarInMethod‚s  cCs#d„}|j|dƒdƒdS(Ncs2‡fd†‰|dkr%ˆ|ƒStd‚dS(Ncs&|dkrdS|ˆ|dƒSdS(Nii((tn(tfact(s+/usr/local/lib/python2.7/test/test_scope.pyR6ªs isx must be >= 0(t ValueError(R((R6s+/usr/local/lib/python2.7/test/test_scope.pyR#©s  iiÐ(R (R R#((s+/usr/local/lib/python2.7/test/test_scope.pyt testRecursion§s cBsZe|dƒe|dƒe|dƒe|dƒe|dƒe|dƒddUdS(NsŠdef unoptimized_clash1(strip): def f(s): from string import * return strip(s) # ambiguity: free or local return f sƒdef unoptimized_clash2(): from string import * def f(s): return strip(s) # ambiguity: global or local return f sœdef unoptimized_clash2(): from string import * def g(): def f(s): return strip(s) # ambiguity: global or local return f sOdef error(y): exec "a = 1" def f(x): return x + y return f sCdef f(x): def g(): return x del x # can't del name s[def f(): def g(): from string import * return strip # global or local? sç def noproblem1(): from string import * f = lambda x:x def noproblem2(): from string import * def f(x): return x + 1 def noproblem3(): from string import * def f(x): global y y = x (R(R ((s+/usr/local/lib/python2.7/test/test_scope.pyttestUnoptimizedNamespaces·sc sd„}|dƒ}|dƒ}|j|dƒdƒ|j|dƒdƒd„}|dƒ}|dƒ}|j|dƒdƒ|j|dƒdƒ‡fd†}d‰|dƒ}|j|dƒd ƒd „}|ddd ƒ}|dd d ƒ}|j|ƒd ƒdS(Ncs ‡fd†S(Ncsˆ|S(N((R(R(s+/usr/local/lib/python2.7/test/test_scope.pytþs((R((Rs+/usr/local/lib/python2.7/test/test_scope.pyR:þsii iiics‡fd†ƒS(Ncs ‡fd†S(Ncsˆ|S(N((R(R(s+/usr/local/lib/python2.7/test/test_scope.pyR:s(((R(s+/usr/local/lib/python2.7/test/test_scope.pyR:s((R((Rs+/usr/local/lib/python2.7/test/test_scope.pyR:scs ‡fd†S(Ncsˆ|S(N((R(R(s+/usr/local/lib/python2.7/test/test_scope.pyR: s((R(R(s+/usr/local/lib/python2.7/test/test_scope.pyR: sics‡‡fd†S(Ncs‡‡‡fd†S(Ncs ˆˆˆS(N(((R'RR (s+/usr/local/lib/python2.7/test/test_scope.pyR:s((R(R'R)(RR (R's+/usr/local/lib/python2.7/test/test_scope.pyR:s((RRR ((RR s+/usr/local/lib/python2.7/test/test_scope.pyR:siii(R tNone( R tf1R R tf2tf3tf8R"R!((Rs+/usr/local/lib/python2.7/test/test_scope.pyt testLambdasüs$        cBsHd„}d„}|je|ƒ|je|ƒdi|jd6UdS(NcsˆGH‡fd†}d‰dS(NcsˆS(N(((R(s+/usr/local/lib/python2.7/test/test_scope.pytinnersi((RA((Rs+/usr/local/lib/python2.7/test/test_scope.pyt errorInOuterscs ‡fd†}|ƒd‰dS(NcsˆS(N(((R(s+/usr/local/lib/python2.7/test/test_scope.pyRAsi((RA((Rs+/usr/local/lib/python2.7/test/test_scope.pyt errorInInnerss– global_x = 1 def f(): global_x += 1 try: f() except UnboundLocalError: pass else: fail('scope of global_x not correctly determined') tfail(t assertRaisestUnboundLocalErrort NameErrorRD(R RBRC((s+/usr/local/lib/python2.7/test/test_scope.pyttestUnboundLocals    cBs•d„}|j|dddƒƒdƒd„}|j|ddƒƒddƒedefƒd eƒUWdQX|jedƒdƒdƒdS(Ncs‡fd†}|S(NcsˆS(N(((tlst(s+/usr/local/lib/python2.7/test/test_scope.pytreturner5s((RIRJ((RIs+/usr/local/lib/python2.7/test/test_scope.pyt makeReturner4siiics‡fd†}|S(NcsˆS(N(((tkwargs(s+/usr/local/lib/python2.7/test/test_scope.pyRJ<s((RLRJ((RLs+/usr/local/lib/python2.7/test/test_scope.pyt makeReturner2;sR(i s*tuple parameter unpacking has been removedscdef makeAddPair((a, b)): def addPair((c, d)): return (a + c, b + d) return addPair idiÈieiÊ(iii(ii(idiÈ(ieiÊ(R Rt SyntaxWarningtlocalst makeAddPair(R RKRM((s+/usr/local/lib/python2.7/test/test_scope.pyttestComplexDefinitions2s    cBs ddUdS(NsÉ# I x = 7 def f(): x = 1 def g(): global x def i(): def h(): return x return h() return i() return g() self.assertEqual(f(), 7) self.assertEqual(x, 7) # II x = 7 def f(): x = 1 def g(): x = 2 def i(): def h(): return x return h() return i() return g() self.assertEqual(f(), 2) self.assertEqual(x, 7) # III x = 7 def f(): x = 1 def g(): global x x = 2 def i(): def h(): return x return h() return i() return g() self.assertEqual(f(), 2) self.assertEqual(x, 2) # IV x = 7 def f(): x = 3 def g(): global x x = 2 def i(): def h(): return x return h() return i() return g() self.assertEqual(f(), 2) self.assertEqual(x, 2) # XXX what about global statements in class blocks? # do they affect methods? x = 12 class Global: global x x = 13 def set(self, val): x = val def get(self): return x g = Global() self.assertEqual(g.get(), 13) g.set(15) self.assertEqual(g.get(), 13) ((R ((s+/usr/local/lib/python2.7/test/test_scope.pyttestScopeOfGlobalStmtLsRcs]dd‡fd†ƒY‰‡fd†}xtdƒD] }|ƒq5W|jˆjdƒdS(NtFoocs,eZdZ‡fd†Z‡fd†ZRS(icsˆjd7_dS(Ni(tcount(R (RS(s+/usr/local/lib/python2.7/test/test_scope.pyt__init__¥scsˆjd8_dS(Ni(RT(R (RS(s+/usr/local/lib/python2.7/test/test_scope.pyt__del__¨s(RRRTRURV((RS(s+/usr/local/lib/python2.7/test/test_scope.pyRS¢scs#ˆƒ‰‡fd†}|ƒdS(NcsˆS(N(((R(s+/usr/local/lib/python2.7/test/test_scope.pyR=­s((R=(RS(Rs+/usr/local/lib/python2.7/test/test_scope.pyR<«s idi((trangeR RT(R R<ti((RSs+/usr/local/lib/python2.7/test/test_scope.pyt testLeaks s   cBs ddUdS(Ns¶def test(x): class Foo: global x def __call__(self, y): return x + y return Foo() x = 0 self.assertEqual(test(6)(2), 8) x = -1 self.assertEqual(test(3)(2), 5) looked_up_by_load_name = False class X: # Implicit globals inside classes are be looked up by LOAD_NAME, not # LOAD_GLOBAL. locals()['looked_up_by_load_name'] = True passed = looked_up_by_load_name self.assertTrue(X.passed) ((R ((s+/usr/local/lib/python2.7/test/test_scope.pyttestClassAndGlobal¶scCs[d„}|dƒdƒ}|jd|ƒ|d=|j|idd6dd6dd 6ƒdS( Ncs‡fd†}|S(Ncs*‡fd†}ˆˆ}ˆd7‰tƒS(Ncsˆ|S(N((R (R(s+/usr/local/lib/python2.7/test/test_scope.pyR!Ósi(RO(RR!tw(R(Rs+/usr/local/lib/python2.7/test/test_scope.pyR"Òs  ((RR"((Rs+/usr/local/lib/python2.7/test/test_scope.pyR#ÑsiiR!RiRiR[(tassertInR (R R#td((s+/usr/local/lib/python2.7/test/test_scope.pyttestLocalsFunctionÏs  cCs^d„}|j|dƒjdƒd„}|dƒj}|jd|ƒ|jd|ƒdS(Ncsdd‡fd†ƒY}|S(NtCcs$eZdZ‡fd†ZeƒRS(i csˆS(N((R (R(s+/usr/local/lib/python2.7/test/test_scope.pytmís(RRRR`RO((R(s+/usr/local/lib/python2.7/test/test_scope.pyR_ës(((RR_((Rs+/usr/local/lib/python2.7/test/test_scope.pyR#êsii csdd‡fd†ƒY}|S(NR_cs,eZˆZ‡fd†ZeeƒƒZRS(csˆS(N((R (R(s+/usr/local/lib/python2.7/test/test_scope.pyR`÷s(RRRR`tlistROR ((R(s+/usr/local/lib/python2.7/test/test_scope.pyR_õs(((RR_((Rs+/usr/local/lib/python2.7/test/test_scope.pyR#ôsRR(R RR t assertNotInR\(R R#tvarnames((s+/usr/local/lib/python2.7/test/test_scope.pyttestLocalsClassßs  csdddl}|jd„ƒz3d‰dd‡fd†ƒY}|jˆdƒWd|jdƒXdS(NiÿÿÿÿcSsdS(N(R;(R(R'R)((s+/usr/local/lib/python2.7/test/test_scope.pyR:si R_cseZ‡fd†ZRS(csˆS(N((R (R(s+/usr/local/lib/python2.7/test/test_scope.pyR# s(RRR#((R(s+/usr/local/lib/python2.7/test/test_scope.pyR_ s((tsystsettraceR R;(R ReR_((Rs+/usr/local/lib/python2.7/test/test_scope.pyttestLocalsClass_WithTraces cCs5d„}|dƒƒ}|j|j|jƒƒdS(Ncsdd‡fd†ƒY}|S(NR_cseZ‡fd†ZˆZRS(csˆS(N((R (R(s+/usr/local/lib/python2.7/test/test_scope.pyR`s(RRR`R(((R(s+/usr/local/lib/python2.7/test/test_scope.pyR_s(((RR_((Rs+/usr/local/lib/python2.7/test/test_scope.pyR#si(R R(R`(R R#tinst((s+/usr/local/lib/python2.7/test/test_scope.pyttestBoundAndFrees csxddl}‡fd†‰d„}dd d„ƒY}|jˆƒ|d|d ƒ|jdƒ|jt|jƒdS( NiÿÿÿÿcsˆS(N((R(R'R)(ttracer(s+/usr/local/lib/python2.7/test/test_scope.pyRj"scsK|\}‰|dkrGˆdkr:d|j|f‰n‡fd†SdS(Nits_%s__%scs t|ˆƒS(N(tgetattr(tobj(tdes(s+/usr/local/lib/python2.7/test/test_scope.pyR:*s(R(tnametklasstgettertkind((Rns+/usr/local/lib/python2.7/test/test_scope.pyt adaptgetter%s    t TestClasscBseZRS((RR(((s+/usr/local/lib/python2.7/test/test_scope.pyRt,stfooiRk((iRk(ReRfR;REt TypeError(R ReRsRt((Rjs+/usr/local/lib/python2.7/test/test_scope.pyttestInteractionWithTraceFuncs    cBs_d„}|dƒ}|jee|jƒy|jiUWnek rMnX|jdƒdS(Ncs ‡fd†S(NcsˆdS(Ni(((R(s+/usr/local/lib/python2.7/test/test_scope.pyR:8s((R((Rs+/usr/local/lib/python2.7/test/test_scope.pyR#7sis9exec should have failed, because code contained free vars(RERvtevalt func_codeRD(R R#R"((s+/usr/local/lib/python2.7/test/test_scope.pyttestEvalExecFreeVars5s   cCsSy tGHWntk rnXdGHd„}|ƒy tGHWntk rNnXdS(Nsbad should not be definedcSs.gdD]}|jƒD] }|^qqdS(Nsa b(tsplit(tstbad((s+/usr/local/lib/python2.7/test/test_scope.pyRMs(R}RG(R R((s+/usr/local/lib/python2.7/test/test_scope.pyttestListCompLocalVarsDs     cCsd„}|dƒƒdS(Ncs‡fd†}|S(NcsˆtdƒdS(Nsx + 1(Rx((R(s+/usr/local/lib/python2.7/test/test_scope.pyR"Ys((RR"((Rs+/usr/local/lib/python2.7/test/test_scope.pyR#Xsi((R R#((s+/usr/local/lib/python2.7/test/test_scope.pyttestEvalFreeVarsVs cs-ddd„ƒY‰‡fd†}|ƒdS(NtSpecialcBseZd„ZRS(cSs tƒdS(N(tnestedcell_get(R ((s+/usr/local/lib/python2.7/test/test_scope.pyRVds(RRRV(((s+/usr/local/lib/python2.7/test/test_scope.pyR€cscs%‡fd†aˆƒf‰d‰dS(NcsˆS(N(((R)(s+/usr/local/lib/python2.7/test/test_scope.pyRisi(R((R€(R)s+/usr/local/lib/python2.7/test/test_scope.pyR#gs (((R R#((R€s+/usr/local/lib/python2.7/test/test_scope.pyttestFreeingCell`scBsHd}i}i}|||U|jd|dƒ|jd|dƒdS(Ns¢def f(): y = 1 def g(): global y return y def h(): return y + 1 return g, h y = 9 g, h = f() result9 = g() result2 = h() itresult2i tresult9(R (R tCODEtlocal_nst global_ns((s+/usr/local/lib/python2.7/test/test_scope.pyt#testGlobalInParallelNestedFunctionsqs  cCsd„}d„}dS(NcSsdS(N((R(((s+/usr/local/lib/python2.7/test/test_scope.pyttopŒscSsdS(N((((s+/usr/local/lib/python2.7/test/test_scope.pyR'Žs((R R‰R'((s+/usr/local/lib/python2.7/test/test_scope.pyttestTopIsNotSignificantŠs (RRR RRRRRR%R*R4R8R9R@RHRQRRRYRZR^RdRgRiRwRzR~RR‚RˆRŠ(((s+/usr/local/lib/python2.7/test/test_scope.pyRs8       %  E    T    !      cCs'tdtfƒttƒWdQXdS(Ns&import \* only allowed at module level(RRNRR(((s+/usr/local/lib/python2.7/test/test_scope.pyt test_main’s t__main__( tunittestttest.test_supportRRRRtTestCaseRR‹R(((s+/usr/local/lib/python2.7/test/test_scope.pyts "ÿÿŽ