a zeʉO@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddZ gdZdgZgdZGd d d ejZGd d d ejZGd ddejZGdddejZGdddejZGdddejZe jGdddejZddZddggfddggfdddddggdggdgfd ggddfggfddd!ddggdggdgfd"ggddfggfddd#ddgd$gdggdgfd%ggddfggfddd&ddgd$gdggdd'gfd(ggddfggfddd)ddggd*ggdgfd+ggddfggfddd,ddggdggd-gfd.ggddfggfddd/ddggd0d1d2gd3gd4d5d6d7d8gd9fd:d;ggfgfdd?ggd@ggfggfdd=dAd?ggdBggfggfdd=d,d?dCggd.ggfggfddd&ddggdggdgfdDggddfggfddEdFdGgfggfddHdFdIgdJdfggfddHdKdLdMdNdOgdPfgdQdfggfddHdRdLdFdSdTgdPfgdUdfggfddHdRd7dFdSdTgdPfgdUdfggfddVggfddWdXdYdZd[ggdfggfdd\d>d]d@ggfggfdd^dRd_d`ggfggfdd^dadbdcgd^dddedfggfgfggfdd^dgdbdcgd^dhdedfgdigfgfggfddjdkdlgdmgdfggfddjdndldogdpgdfggfddqdndrdsdtduggfdfggfddvdadcgdwdddxddfgfgggfggfddvdadcgggdfgfggfddyggfddzd{d|gfggfdd}dkd~dgdfggfddddgfggfddggfddggfddWd&dYdZdggdfggfddWddYdZdggdfggfddWd)dLdddgdPfdd+ggdfggfddWddLdddgdPfddggdfggfddWdd7dddgdPfddggdfggfddddddLdddgd9fddLdddgdPfdgdfgffggfddddddddddgdfddddgdfgffggfdddddddddLdddgdPfdgdfgffggfddddddddddgdfgffggfddd&dd&dddLdddgdPfdgdfgffggfdddddggdggdgfddddddrddggfffggddfggfdddddggdggdgfdddddgdgdfggddfggfdddddggdggdgfdddgdgdfggddfggfddd#d:d#ddgd:ddJgdgfdgffggfddd>dd>ddddddgfd9fdgffggfdddddggdggdgfddddddddgdfgffggddfggfdddddggdggdgfdgddrddggfdrdddggfgddfggfdddddggdggdgfdgddrddggfdrdddggfgddfggfdd=dd?ggdgddrddggfdrdddggfgfggfdddddggdggdgfdgdrddddddddgdfgfggfgddfggfdddddggdggdgfdgdgddfggfddggfddd)ddd$ggdggdgfd+ggddfggfdddddd$ggddggdgfdggddfggfddd!ddd$gdgdddgddgdgfdggddfggfdddddd$gdgdddgddgdgfdggddfggfdddddd$ggdggddgfdggddfggfddd!ddd$gddgdggdgdfdggddfggfdddAddd$gdgddgdgdddgfdggddfggfdddddd$gdgddgdgdddgfdggddfggfdddddd$gdgddgdgdddgfdggddfggfdddddd$gdgddgdgdddgfdggddfggfgCZddgfgZddddKddd gffd d dd d dggdggdgfdffdd:dKdgdgffdd:dggffdddKdgffdd:ddgdgffddddddddgdfgffddddddddgdfgffddddLdddgd9fddLdddgdPfdgdfgffddϐddLdddgd9fddLddd gdPfd!gdfgffddϐddLdddgd9fdd7ddd gdPfd!gdfgffddddLdddgd9fddLdddgdPfdgdfgffddddLdddgd9fddLddd gdPfd!gdfgffddddLdddgd9fdd7ddd gdPfd!gdfgffddddLdddgd9fddLdddgdPfdgdfgffddddLdddgd9fddLddd gdPfd!gdfgffddddLdddgd9fdd7ddd gdPfd!gdfgffdd"dRd#d$d$gdd%gffddrdkd&gd'd(d)gffddrd{d&dʐd*d7d+d,d-gd9fd9fggffddrdXd&dd.ddd/d0gdfgfggffd1d2d3d4d5dd7dKgd6d9ffdd7dgd9ffddLdFgd7d9ffddLdKgd6d9ffddLdgd9ffddrdkd8d9ggffg#ZedS(:N)dedent)supportcCs|dust|tttfr|St|tr4dd|DS|jjg}t|drt|dr||j |j ft|drt|dr|d|j |j f7<|j durt|S|j D]}|tt||qt|S)NcSsg|] }t|qS)to_tuple).0errA/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_ast.py zto_tuple..lineno col_offset end_linenoend_col_offset) isinstancestrintcomplexlist __class____name__hasattrappendr r r r_fieldstuplergetattr)tresultfrrrrs    r)CNonez'module docstring'z def f(): passzdef f(): 'function docstring'zdef f(a): passzdef f(a=0): passzdef f(*args): passzdef f(**kwargs): passzGdef f(a, b=1, c=None, d=[], e={}, *args, f=42, **kwargs): 'doc for f()'z class C:passz class C: 'docstring for class C'zclass C(object): passzdef f():return 1zdel vv = 1za,b = cz (a,b) = cz [a,b] = czv += 1zfor v in v:passz while v:passz if v:passzif a: pass elif b: passz(if a: pass elif b: pass else: passzwith x as y: passzwith x as y, z as q: passzraise Exception('string')z$try: pass except Exception: passztry: pass finally: passzassert vz import syszfrom sys import vzglobal v1passzfor v in v:breakzfor v in v:continuezfor a,b in c: passzfor (a,b) in c: passzfor [a,b] in c: passzL( ( Aa , Bb ) for Aa , Bb in Cc )z"{a : b for w in x for m in p if g}z{a : b for v,w in x}z{r for l in x if g}z{r for l,m in x}z3async def f(): 'async function' await something()z,async def f(): async for e in i: 1 else: 2z$async def f(): async with a as b: 1z{**{1:2}, 2:3}z {*{1, 2}, 3}z$async def f(): [i async for b in c]z'@deco1 @deco2() @deco3(1) def f(): passz-@deco1 @deco2() @deco3(1) async def f(): passz'@deco1 @deco2() @deco3(1) class C: passz!@deco(a for a in b) def f(): pass@a.b.c def f(): passz(a := 1)zdef f(a, /,): passzdef f(a, /, c, d, e): passzdef f(a, /, c, *, d, e): passz'def f(a, /, c, *, d, e, **kwargs): passzdef f(a=1, /,): passzdef f(a=1, /, b=2, c=4): passz def f(a=1, /, b=2, *, c=4): passzdef f(a=1, /, b=2, *, c): passz*def f(a=1, /, b=2, *, c=4, **kwargs): passz(def f(a=1, /, b=2, *, c, **kwargs): passz1+2)#rza and ba + bznot vz lambda:Nonez{ 1:2 }{}z{None,}z&{ 1 : 2 }z[a for b in c if d]z(a for b in c if d)z[(a,b) for a,b in c]z[(a,b) for (a,b) in c]z[(a,b) for [a,b] in c]z{(a,b) for a,b in c}z{(a,b) for (a,b) in c}z{(a,b) for [a,b] in c}z((a,b) for a,b in c)z((a,b) for (a,b) in c)z((a,b) for [a,b] in c)z 1 < 2 < 3zf(1,2,c=3,*d,**e) f(*[0, 1])zf(a for a in b)Z10z'string'a.bza[b:c]vz[1,2,3]z[]z1,2,3z(1,2,3)()za.b.c.d(a.b[1:2])c@s eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zejd3d4Zd5d6Zd7d8Z d9d:Z!d;d<Z"d=d>Z#d?S)@ AST_TestscCs0t|tsdSd|jvrdS|dko.|dS)NFastASTr)rtype __module__isupper)selfnamenoderrr _is_ast_nodes   zAST_Tests._is_ast_nodecCst|tjr|jdurdSt|tjtjtjfrT|j|jf}| |||j|jf}|jD]h}t ||}t|t r|}|r|dkr|dj|djf}|D]}| ||qqZ|durZ| ||qZdS)Ndecorator_listr) rr+r,rexprstmtZ excepthandlerr r ZassertGreaterEqualrr_assertTrueorder)r0ast_nodeZ parent_posZnode_posr1valueZ first_poschildrrrr7s        zAST_Tests._assertTrueordercCst}||jdd|_||jd||jdd|t|jWdn1sb0Y|t tdWdn1s0YdS)Nr*foobar) r+r, assertEqualrr<__dict__ assertRaisesAttributeErrorvararg TypeErrorr0xrrrtest_AST_objectss $ zAST_Tests.test_AST_objectscCsLGddd}t}||_||j_t|j}~t||dS)Nc@s eZdZdS)z0AST_Tests.test_AST_garbage_collection..XNrr. __qualname__rrrrX$srI) r+r,rEaweakrefrefr gc_collect assertIsNone)r0rIrJrLrrrtest_AST_garbage_collection#s z%AST_Tests.test_AST_garbage_collectionc CsttdfttdfttdffD]\}}}t||D]\}}|jd|d<t|d|t j }| t ||| |dWdn1s0Y|jd||d t|d|Wdq01s0Yq0qdS) NexecsingleevalZparsing)actioninput?)rrZ compiling)rSrTkind) exec_tests exec_results single_testssingle_results eval_tests eval_resultszipsubTestcompiler+ PyCF_ONLY_ASTr>rr7)r0rToutputrVioast_treerrr test_snippets.s*zAST_Tests.test_snippetscCs0ttt}|D]}t|}t|ddqdS)NrP)rWrYr[r+parser_)r0Zsnippets_to_validateZsnippettreerrrtest_ast_validation:s  zAST_Tests.test_ast_validationcCs<tdjdjj}||j||j||jdS)Nzx[::]r) r+rgbodyr9slicerNupperlowerstep)r0Zslcrrr test_sliceAs  zAST_Tests.test_slicecCs tdjd}||jdS)Nzfrom . import yr)r+rgrjrNmodule)r0imrrrtest_from_importGszAST_Tests.test_from_importcCs>td}||jdtjd|jd_t|dddS)Nzfrom __future__ import divisionrz __future__ rP)r+rgassertIsInstancerj ImportFromstriprpr_)r0modrrr!test_non_interned_future_from_astKs z+AST_Tests.test_non_interned_future_from_astcCs||ttjtj|ttjtj|ttjtj|ttjtj|ttjtj|ttj tjdSN) assertTrue issubclassr+Forr6Namer5r, comprehensionZGtr0rrrtest_base_classesQs zAST_Tests.test_base_classescCsRtjD]B\}}|||r |dkr(q |}t|tjr |t|jt q dS)NZIndex) r+r?itemsr3rr,r>r-rr)r0r1itemrErrrtest_field_attr_existenceYs  z#AST_Tests.test_field_attr_existencecCst}||jd|t|jWdn1s<0Y||jtjt dd}||jd||jddS)N) posonlyargsargsrB kwonlyargs kw_defaultskwargdefaultsr=) r+ argumentsr>rr@rArrNrBrangerDrrrtest_argumentsds $ zAST_Tests.test_argumentscCs t}d|_||jddS)Ni)r+Numrr>rDrrrtest_field_attr_writableqsz"AST_Tests.test_field_attr_writablecCst}||jd|t|jWdn1s<0Y|t|jWdn1sl0Ytd}||jd||jd|t|jWdn1s0Y|t|j Wdn1s0Ytjdd}||jdtjddd}||jd||jd||jd||jd|t tjddd|jt tjddddd|tj dddj d|tjdddj d| t d tjddd Wdn1s0Y| t d tj ddd Wdn1s&0Y|tdjd|td jd |tdjd|tdjd|tdjd|tdjd|tdjd|tdjd|t djd|t d jd |t djd|t djd|t djd|t djd|t djd|t djd|t djddS)N)r9rVr;r=r rrZbar)fooz(Num got multiple values for argument 'n'nz1Constant got multiple values for argument 'value'r9@@4242TF.)r+rr>rr@rAr9rr r<rCConstantrassertRaisesRegexStrsBytesassertIs NameConstantrDrrrtest_classattrswsZ $ $  $ $ ..zAST_Tests.test_classattrscCs|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|tttjdS)Nr;rrrrTF) r>r-r+rrrrrEllipsisrrrr test_realtypeszAST_Tests.test_realtypecCs|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|tttj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj|ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| ttdtj| tttj| tttj| tttj| tttj| tttjGd d d t }|tt|dtj| tt|dtjdS) Nr;g@y@rrTF.c@s eZdZdS)z$AST_Tests.test_isinstance..SNrGrrrrSr r) rzrr+rrrrrr assertFalser)r0rrrrtest_isinstancesPzAST_Tests.test_isinstancecCsGdddtj}Gdddtj}|d}||jd||jd|t|||t|||t|tj|t|||ttd||dd}||jd|t||dS)NcseZdZfddZZS)z$AST_Tests.test_subclasses..Ncstj|i|d|_dS)Nspam)super__init__z)r0rkwargsrrrrsz-AST_Tests.test_subclasses..N.__init__)rr.rHr __classcell__rrrrNsrc@s eZdZdS)z%AST_Tests.test_subclasses..N2NrGrrrrN2srr;rr) r+rr>rrr-rzrr)r0rrrrrrtest_subclassess zAST_Tests.test_subclassescCs*tdg}t|g}||j|dS)Nr;)r+rModuler>rj)r0rjrErrr test_modules  zAST_Tests.test_modulec Cst}||jdd|_||jdtd}td}t}t|||}||j|||j|||j |tddd}||jd||jd||j dtjddddd}||jd||jd||j d||j d| t tjdddd|j t tjddddddtjddddd }||jd||jd||j d||j dtjdddd d }||jd dS) N)leftoprightrrr=rr)rrrr r;) foobarbaz) r+BinOpr>rrrAddrrrr r@rC)r0rEZn1Zn3Zaddoprrrtest_nodeclassess:  zAST_Tests.test_nodeclassescCst}||jddS)Nr)r+ZSubr>rrDrrrtest_no_fields2szAST_Tests.test_no_fieldsc Csddl}|g}zddl}||Wnty6Yn0gd}|D]H}|D]>}ddtDD]*}||||}|t|t|q^qLqDdS)Nr)rrr=css|]}t|dddVqdS)rUrPiN)r_)rrbrrr Br z*AST_Tests.test_pickling..) picklecPickler ImportErrorrWloadsdumpsr>r) r0rZmodsrZ protocolsrwprotocolr+ast2rrr test_pickling7s zAST_Tests.test_picklingcCstddd}ttjtjfi|fi|gg}|t}t|ddWdn1s`0Y|dt |j dS)Nr=rr r rsrPzbut got .bad_normalize normalizeuϕ) unicodedatar swap_attrr@rCr+rg)r0rrrrrtest_issue31592eszAST_Tests.test_issue31592cCsDtd}|jdj}|j}|j}||jd||jd||jd||jd||jd||jdtd}|jdj}|j}|j}||jd||jd||jd||j d ||jd||jd||jd ||j d ||jd||jd||jd||j ddS) Nz4+5+6+7rrrz 4+5-\ 6-7rrr=) r+rgrjr9rr>r rr r )r0rhZ parent_binopZ child_binopZgrandchild_binoprrr test_issue18374_binop_col_offsetos4    z*AST_Tests.test_issue18374_binop_col_offsetcCs.td}|jdjdj}||jddS)Nr#rr)r+rgrjr4r9r>r)r0rhZattr_brrr*test_issue39579_dotted_name_end_col_offsets z4AST_Tests.test_issue39579_dotted_name_end_col_offsetcCs|tjjd|tjjd|tjjd|tjjdddtjD}dtjdj|d<| tjj d |dS) Nz0withitem(expr context_expr, expr? optional_vars)GtEz%Name(identifier id, expr_context ctx)zBcmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIncSsg|]}d|jqS)z | )__doc__)rr2rrrr r z5AST_Tests.test_ast_asdl_signature..zexpr = r ) r>r+withitemrrr}Zcmpopr5__subclasses__ZassertCountEqualsplit)r0Z expressionsrrrtest_ast_asdl_signaturesz!AST_Tests.test_ast_asdl_signaturecCsJtjddd|ttjdddWdn1s<0YdS)Nzf"{x=}")rr)Zfeature_version)rr)r+rgr@ SyntaxErrorrrrrtest_issue40614_feature_versions z)AST_Tests.test_issue40614_feature_versionc CsndD]d}tt|t}t||td|dt|ddWdq1s^0YqdS)N)TrueFalserzName node can't be used with 'z ' constantrsrR)r+rr}rrrrr_)r0Zconstantr5rrrtest_constant_as_names  zAST_Tests.test_constant_as_nameN)$rr.rHr3r7rFrOrerirorrrxrrrrrrrrrrrrrrrrr cpython_onlyrrrrrrrrrrr*s@    < /,   r*c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/ZdS)0ASTHelpers_TestNcCs6td}tdddtj}|t|t|dS)Nz foo(1 + 1)z rP)r+rgr_r`r>dump)r0rJbrrr test_parses zASTHelpers_Test.test_parsec Csfz ddWnTty`|t}tdWdn1sD0Y||jjYn0dS)Nrrz'\U') Exceptionr@rr+ literal_evalZassertIsNotNoner __context__r0rrrrtest_parse_in_errors    (z#ASTHelpers_Test.test_parse_in_errorcCsLtd}|t|d|tj|ddd|tj|ddddS) Nspam(eggs, "and cheese")zModule(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), args=[Name(id='eggs', ctx=Load()), Constant(value='and cheese')], keywords=[]))], type_ignores=[])Fannotate_fieldszbModule([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), Constant('and cheese')], []))], [])Tinclude_attributesaModule(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=4), args=[Name(id='eggs', ctx=Load(), lineno=1, col_offset=5, end_lineno=1, end_col_offset=9), Constant(value='and cheese', lineno=1, col_offset=11, end_lineno=1, end_col_offset=23)], keywords=[], lineno=1, col_offset=0, end_lineno=1, end_col_offset=24), lineno=1, col_offset=0, end_lineno=1, end_col_offset=24)], type_ignores=[])r+rgr>rr0r2rrr test_dumps  zASTHelpers_Test.test_dumpcCsTtd}|tj|ddd|tj|dddd|tj|d dd d dS) Nrr)indentzModule( body=[ Expr( value=Call( func=Name(id='spam', ctx=Load()), args=[ Name(id='eggs', ctx=Load()), Constant(value='and cheese')], keywords=[]))], type_ignores=[])F )rrzModule( [ Expr( Call( Name('spam', Load()), [ Name('eggs', Load()), Constant('and cheese')], []))], [])T)rraModule( body=[ Expr( value=Call( func=Name( id='spam', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=4), args=[ Name( id='eggs', ctx=Load(), lineno=1, col_offset=5, end_lineno=1, end_col_offset=9), Constant( value='and cheese', lineno=1, col_offset=11, end_lineno=1, end_col_offset=23)], keywords=[], lineno=1, col_offset=0, end_lineno=1, end_col_offset=24), lineno=1, col_offset=0, end_lineno=1, end_col_offset=24)], type_ignores=[])rrrrrtest_dump_indents   z ASTHelpers_Test.test_dump_indentcCstjddd}|t|d|tj|dddtjtjdtd ddd }|t|d |tj|d d d|tj|ddd|tj|d dddtjtjdtd d}|t|d|tj|d d ddS)NrrrzRaise()TrzRaise(lineno=3, col_offset=4)r)idctx)excr r z#Raise(exc=Name(id='e', ctx=Load()))FrzRaise(Name('e', Load()))z;Raise(exc=Name(id='e', ctx=Load()), lineno=3, col_offset=4))rrz0Raise(Name('e', Load()), lineno=3, col_offset=4))causez%Raise(cause=Name(id='e', ctx=Load()))zRaise(cause=Name('e', Load())))r+Raiser>rr}rrrrrtest_dump_incomplete s6   z$ASTHelpers_Test.test_dump_incompletecCstjddd}ttd|jj|j_|tj|dddtjddddd }t|tjddd }| |j | |j ||j d||j ddS) N1 + 1rRmoder=TrzExpression(body=BinOp(left=Constant(value=1, lineno=1, col_offset=0, end_lineno=1, end_col_offset=1), op=Add(), right=Constant(value=2, lineno=1, col_offset=4, end_lineno=1, end_col_offset=5), lineno=1, col_offset=0, end_lineno=1, end_col_offset=5))r)r r r r)r r )r+rg copy_locationrrjrr>rCallrNr rr r )r0srcnewrrrtest_copy_location(s  z"ASTHelpers_Test.test_copy_locationc Csltd}|jtttdttdgg| |t |d|_ | tj |ddddS)Nz write("spam")rZeggsTraModule(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=5), args=[Constant(value='spam', lineno=1, col_offset=6, end_lineno=1, end_col_offset=12)], keywords=[], lineno=1, col_offset=0, end_lineno=1, end_col_offset=13), lineno=1, col_offset=0, end_lineno=1, end_col_offset=13), Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=0), args=[Constant(value='eggs', lineno=1, col_offset=0, end_lineno=1, end_col_offset=0)], keywords=[], lineno=1, col_offset=0, end_lineno=1, end_col_offset=0), lineno=1, col_offset=0, end_lineno=1, end_col_offset=0)], type_ignores=[])) r+rgrjrrr r}rrr>rmaxDiffrr0rrrrtest_fix_missing_locations8s  z*ASTHelpers_Test.test_fix_missing_locationscCstjddd}|tj|dd||tj|dddtjddd}|tj|jdd|j|tj|dddtjtd tggd d }|t|j d | t|j dS) Nr rRr rrTrzExpression(body=BinOp(left=Constant(value=1, lineno=4, col_offset=0, end_lineno=4, end_col_offset=1), op=Add(), right=Constant(value=1, lineno=4, col_offset=4, end_lineno=4, end_col_offset=5), lineno=4, col_offset=0, end_lineno=4, end_col_offset=5))testr)funcrkeywordsr r=) r+rgr>Zincrement_linenorrjr r}rr rNr rrrrtest_increment_linenoLsz%ASTHelpers_Test.test_increment_linenocCsHtjddd}tt|j}||djd||ggddS)Nfoo()rRr rr)rr)r+rgrZ iter_fieldsrjr>popr)r0r2drrrtest_iter_fieldsdsz ASTHelpers_Test.test_iter_fieldscCstjddd}|ttt|jdt|j}|t|jd|t|j d|t|j d|t t|ddS) Nzspam(23, 42, eggs='leek')rRr rrr;z1keyword(arg='eggs', value=Constant(value='leek'))) r+rgr>lenrZiter_child_nodesrjnextrr9r)r0r2iteratorrrrtest_iter_child_nodesjs z%ASTHelpers_Test.test_iter_child_nodescCstd}|t|dtd}|t|jddtd}|t|jddtd}|t|jdddS)Nz"""line one line two"""zline one line twoz&class foo: """line one line two"""rz&def foo(): """line one line two"""z#async def foo(): """spam ham"""zspam ham)r+rgr> get_docstringrjrrrrtest_get_docstringus     z"ASTHelpers_Test.test_get_docstringcCs.|ttdtd}|t|td}|t|td}|t|jdtd}|t|jdtd}|t|jdtd}|t|jdtd}|t|jdtd }|t|jdtd }|t|jddS) Nzx = "not docstring"zdef foo(): passzclass foo: passrz class foo: x = "not docstring"z class foo: def bar(self): passz def foo(): x = "not docstring"zasync def foo(): passz&async def foo(): x = "not docstring")rNr+r!rgrjrrrrtest_get_docstring_nones&         z'ASTHelpers_Test.test_get_docstring_nonecCstd}||jdjd||jdjd||jdjdjd||jdjdjd||jdjdjdjd||jdjdjdjd||jdjdjd||jdjdjd||jdjd||jdjd dS) Nz"""line one line two""" def foo(): """line one line two""" def bar(): """line one line two""" """line one line two""" """line one line two""" rrr=rr )r+rgr>rjr r rrrr:test_multi_line_docstring_col_offset_and_lineno_issue16806s  zJASTHelpers_Test.test_multi_line_docstring_col_offset_and_lineno_issue16806cCs:td}|jdjd}||jd||jddS)Nz if a: pass elif b: pass rrr+rgrjorelser>r r r0r2Z elif_stmtrrrtest_elif_stmt_start_positions z-ASTHelpers_Test.test_elif_stmt_start_positioncCs:td}|jdjd}||jd||jddS)Nz/if a: pass elif b: pass else: pass rrr)r+rrr'test_elif_stmt_start_position_with_elses z7ASTHelpers_Test.test_elif_stmt_start_position_with_elsecCs<td}|jdjjd}||jd||jddS)Nr&rrr%)r+rgrjr9rr>r r)r0r2Z starred_exprrrr*test_starred_expr_end_position_within_calls z:ASTHelpers_Test.test_starred_expr_end_position_within_callcCs@|tdgd|tdddi|tdd|tdhd |td d |td t|ttjd |tdd|tdd|tdd|tdd|tdd|tdd|ttdd|ttjd|ttjd|ttjddS)Nz [1, 2, 3]rr=rz {"foo": 42}rr;z(True, False, None))TFNz {1, 2, 3}>rr=rzb"hi"shizset()r6z+6z-6iz3.25g @z+3.25z-3.25g z-0.0z++6z+Truez2+3)r>r+rsetr@rreprrrrrtest_literal_evals"z!ASTHelpers_Test.test_literal_evalcCs>|tdd|tdd|tdd|tdd|td d |td d |td d|tdd|tdd|tdd|tdd|tdd|tdd |ttjd|ttjd|ttjd|ttjd|ttjddS)NZ6jy@z-6jyz6.75jy@z-6.75jyz3+6jy@@z-3+6jy@z3-6jy@z-3-6jyz 3.25+6.75jy @@z -3.25+6.75jy @z 3.25-6.75jy @z -3.25-6.75jy z(3+6j)z-6j+3z-6j+3jz3+-6jz3+(0+6j)z-(3+6j))r>r+rr@rrrrrtest_literal_eval_complexs$z)ASTHelpers_Test.test_literal_eval_complexcCsptjtdtdgtdgd}|ttj|tjtdgtdtdgd}|ttj|dS)Nrr=r)keysvalues)r+Dictrr@rr)r0Z malformedrrr&test_literal_eval_malformed_dict_nodess&&z6ASTHelpers_Test.test_literal_eval_malformed_dict_nodescCsxtjdtjddgddddg}t|g}|t}t|ddWdn1sX0Y|dt|j dS)Ntimesleepr1rpnameslevelr r rrPzinvalid integer value: None) r+rualiasrr@rr_rrr)r0rjrwrrrrtest_bad_integers   *z ASTHelpers_Test.test_bad_integercCsVtjdtjddgddddg}t|g}t|dd}i}t|||d|dS)Nr:r;r<rr=rrP)r+rur@rr_rPr)r0rjrwcodensrrrtest_level_as_nones    z"ASTHelpers_Test.test_level_as_nonec Cstjtddd}||_|tJt"tt |ddWdn1sV0YWdn1st0YdSNr)rr r rsrR r+UnaryOpNotoperandr@RecursionErrorrZinfinite_recursionr_rrrrrtest_recursion_directs   z%ASTHelpers_Test.test_recursion_directc Cstjtddd}tjtddd}||_||_|tJt"tt |ddWdn1sp0YWdn1s0YdSrErF)r0rrrrrtest_recursion_indirect s  z'ASTHelpers_Test.test_recursion_indirect)rr.rHrrrrrrrrrrr r"r$r(r,r-r.r4r5r9rArDrKrLrrrrrs0=   rc@seZdZd`edddZdaedddZdbdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdd?Z!d@dAZ"dBdCZ#dDdEZ$dFdGZ%dHdIZ&dJdKZ'dLdMZ(dNdOZ)dPdQZ*dRdSZ+dTdUZ,dVdWZ-dXdYZ.dZd[Z/d\d]Z0d^d_Z1dS)cASTValidatorTestsNrPrcCsxd|_|_t||dur,t|d|nH||}t|d|Wdn1sX0Y||t|jdS)Nrrs) r r r+rr_r@rrr)r0rwmsgr rrrrrrws   *zASTValidatorTests.modcCs(tt|gg}|j|||ddS)NrN)r+rrrw)r0r2rOrrwrrrr5#szASTValidatorTests.exprcCst|gg}|||dSry)r+rrw)r0r6rOrwrrrr6'szASTValidatorTests.stmtc CsTtttdtg}||ddttdt}||dddS)NrEmust have Load contextrQrR)r+ Interactiverr}Storerwr)r0rrrrr+szASTValidatorTests.test_modulec sdfdd }tdtdtg}|||dd|||dd|||dd||tdgd d ||td gd d tdtdtg}|||tdtgddtdtdttdtdtg}|||dtdtgdddS)Nc sZ|dur g}|durg}|dur$g}|dur0g}|dur.argumentsrErrP)r)rr)rz"more positional defaults than argsr)rz3length of kwonlyargs is not the same as kw_defaults)rrrJry)rr)NNNNNNN)r+argr}rRrr)r0rTcheckrrrrSr_check_arguments1s4z"ASTValidatorTests._check_argumentsc Cstggdggdg}td|ggd}||dtd|tgtdtgd}||dtd|tggtdt}||ddd}|||jdS)NrEzempty body on FunctionDefrPcSstd|tggdSNrE)r+ FunctionDefPassrrrrrT]sz+ASTValidatorTests.test_funcdef..fac)r+rrZr6r[r}rRrX)r0rJrrTrrr test_funcdefSs    zASTValidatorTests.test_funcdefc Csd dd}||tdtgdd||tdtdtgdd||gdd||dgdd ||tdtgd ddS) NcSsH|dur g}|durg}|dur*tg}|dur6g}td||||S)NZmyclass)r+r[ClassDef)basesrrjr4rrrclsbs  z,ASTValidatorTests.test_classdef..clsrE)r^rP)rrzempty body on ClassDefNone disallowed)r4)NNNN)r6r+r}rRkeyword)r0r_rrr test_classdefas "zASTValidatorTests.test_classdefc CsJ|tgd|tdgd|ttdtgddS)Nzempty targets on Deleter`rEzmust have Del context)r6r+Deleter}rrrrr test_deletevs zASTValidatorTests.test_deletec Cs|tgtdd|tdgtdd|ttdtgtdd|ttdtgtdtddS)Nrzempty targets on Assignr`rEmust have Store contextrUrP)r6r+Assignrr}rrRrrrr test_assign|s"zASTValidatorTests.test_assignc Cspttdtttdt}||dttdtttdt}||ddS)NrErUrerP)r+ AugAssignr}rrr6rR)r0Zaugrrrtest_augassigns z ASTValidatorTests.test_augassignc Cstdt}tdt}t}|t||ggd|ttdt||ggd|t|tdt|ggdttdt}|t|||ggd|t|||g|gddS)NrErUzempty body on ForrerP)r+r}rRrr[r6r|r)r0rErUprrrrtest_fors  zASTValidatorTests.test_forc Cs~|ttdggd|ttdttggd|ttdtgttdtgddS)Nrzempty body on WhilerErP)r6r+Whilerr}rRr[rrrrr test_whiles"zASTValidatorTests.test_whilec Cs|ttdggdttdttgg}||dttdttdtgg}||dttdtgttdtg}||ddS)Nrzempty body on IfrErP)r6r+Ifrr}rRr[r)r0rbrrrtest_ifs  ( zASTValidatorTests.test_ifcCst}|tg|gdttdd}|t|ggdttdtd}|t|g|gdttdtdt}|t|g|gddS)Nzempty items on Withrzempty body on WithrErPre) r+r[r6Withrrr}rRr)r0rjrbrrr test_withszASTValidatorTests.test_withcCsptdtd}||dttdtd}||dttdtdt}||ddS)Nrz!Raise with cause but no exceptionrErPr)r+rrr6r}rR)r0rrrr test_raises   zASTValidatorTests.test_raisec Csxt}tggg|g}||dtttdtggg|g}||dt|gggg}||dt|gg|g|g}||dt|gtddgggg}||dttdtd|gg}|t|g|ggdtdd|gg}t|g|ttdtg|g}||dt|g||gttdtg}||ddS)Nzempty body on TryrErPz-Try has neither except handlers nor finalbodyz%Try has orelse but no except handlerszempty body on ExceptHandlerrU)r+r[Tryr6rr}rR ExceptHandler)r0rjrrrrrtest_trys$ &    ( (zASTValidatorTests.test_tryc CsT|ttdtddttdttdt}||ddS)NrErPrU)r6r+Assertr}rRr)r0Zassrtrrr test_assertszASTValidatorTests.test_assertcCs|tgddS)Nzempty names on Import)r6r+Importrrrr test_importszASTValidatorTests.test_importcCs>tdtddgd}||d|tdgdddS)NrEizNegative ImportFrom levelrzempty names on ImportFrom)r+rur@r6)r0imprrrtest_importfroms z!ASTValidatorTests.test_importfromcCs|tgddS)Nzempty names on Global)r6r+Globalrrrr test_globalszASTValidatorTests.test_globalcCs|tgddS)Nzempty names on Nonlocal)r6r+ZNonlocalrrrr test_nonlocalszASTValidatorTests.test_nonlocalcCs&ttdt}||ddSNrErP)r+rr}rRr6rrrr test_exprszASTValidatorTests.test_exprc Csttg}||dtttdg}||dtttddg}||dtttdtdtg}||ddS)Nzless than 2 valuesrrr`rErP)r+BoolOpAndr5rr}rR)r0rrrr test_boolops   &zASTValidatorTests.test_boolopcCs,tttdt}||ddSr)r+rGrHr}rRr5)r0urrr test_unaryopszASTValidatorTests.test_unaryopc CsPtggdggdg}|t|tdtddd}|||jdS)NrErPcSst|tdtSrY)r+Lambdar}rrrrrrTsz*ASTValidatorTests.test_lambda..fac)r+rr5rr}rRrX)r0rJrTrrr test_lambdas zASTValidatorTests.test_lambdacCsXtdt}tdt}|||f|||f|||ffD]}|tj|dq.wrap)r+r~r}rRrr5r)r0rTrrrrSr _simple_comp!s zASTValidatorTests._simple_compcCs|tjdSry)rr+ListComprrrr test_listcomp*szASTValidatorTests.test_listcompcCs|tjdSry)rr+SetComprrrr test_setcomp-szASTValidatorTests.test_setcompcCs|tjdSry)rr+ GeneratorExprrrrtest_generatorexp0sz#ASTValidatorTests.test_generatorexpcCsttdttdtgd}ttdttdt|g}||dttdttdt|g}||ddd}||dS)NrUrjrrErPcSs.tdt}tdt}t|||S)NrErU)r+r}rDictComp)compskr(rrrfactory<sz0ASTValidatorTests.test_dictcomp..factory)r+r~r}rRrrr5r)r0rcrrrr test_dictcomp3s  zASTValidatorTests.test_dictcompc Cs@|ttdtd|ttdtddS)NrEzmust have Load)r5r+ZYieldr}rRZ YieldFromrrrr test_yieldBszASTValidatorTests.test_yieldcCstdt}t|tgg}||dt|tgtdtdg}||dttdtg|g}||t|tgtdg}||dS)NrEzno comparatorsrrz,different number of comparators and operandsZblah)r+r}rCompareZInr5r)r0rcomprrr test_compareFs $  zASTValidatorTests.test_comparecCstdt}tdtg}tdtdtg}ttdt||}||dt|dg|}||dtdtdtg}t|||}||ddS)NrErUwrrPr`)r+r}rrar rRr5)r0rrrcallZ bad_keywordsrrr test_callQs  zASTValidatorTests.test_callcCszGdddt}Gdddt}Gdddt}dD]}|t|q4|||fD]}|jt|dtd qZdS) Nc@s eZdZdS)z*ASTValidatorTests.test_num..subintNrGrrrrsubint^src@s eZdZdS)z,ASTValidatorTests.test_num..subfloatNrGrrrrsubfloat`src@s eZdZdS)z.ASTValidatorTests.test_num..subcomplexNrGrrrr subcomplexbsr)0Zhelloz invalid typerN)rfloatrr5r+rrC)r0rrrobjrrrtest_num]szASTValidatorTests.test_numcCs.ttdtdt}||ddSr)r+ Attributer}rRrr5)r0attrrrrtest_attributeisz ASTValidatorTests.test_attributec Csttdttdt}||dtdt}t|tdtt}||dtdt}|ddfd|dfdd|ffD](}tj|}|t||tdqtgt}|t||tt|gt}|t||tddS)NrErrPrU) r+ Subscriptr}rRrrr5SliceTuple)r0subrErrslrrrtest_subscriptms&    z ASTValidatorTests.test_subscriptc CsNtttdttgt}t|gtd}||ddS)NrErre) r+ListStarredr}rrRrfrr6)r0rassignrrr test_starreds  zASTValidatorTests.test_starredcCs@||dgtd||tdtgtddSr)r5r+rr}rR)r0rTrrr _sequenceszASTValidatorTests._sequencecCs|tjdSry)rr+rrrrr test_listszASTValidatorTests.test_listcCs|tjdSry)rr+rrrrr test_tupleszASTValidatorTests.test_tuplecCs|tddS)Nr)r5r+rrrrrtest_nameconstantsz#ASTValidatorTests.test_nameconstantc Cstjtj}ddt|D}|ddg|D]}||ltj||}t |ddd}| }Wdn1s~0Yt ||}t ||dWdq41s0Yq4dS) NcSsg|]}|dr|qS)z.py)endswith)rfnrrrr r z;ASTValidatorTests.test_stdlib_validates..ztest/test_grammar.pyztest/test_unpack_ex.pyrrzutf-8)encodingrP) ospathdirnamer+__file__listdirextendr^joinopenreadrgr_)r0Zstdlibtestsrprfpsourcerwrrrtest_stdlib_validatess & z'ASTValidatorTests.test_stdlib_validates)NrP)N)N)2rr.rHrrwr5r6rrXr\rbrdrgrirkrmrorqrsrvrxrzr|r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrMs\  "         rMc@sfeZdZdZddZddZddZdd Zd d Zd d Z ddZ e j ddZ ddZddZdS) ConstantTestsz$Tests on the ast.Constant node type.cCs\td}|jdj}tj|d}t||||jd_t|dd}i}t|||dS)Nzx = 123rrrfrPrE)r+rgrjr9rr r_rP)r0r9rhr2new_noderBrCrrrcompile_constants       zConstantTests.compile_constantcCsN|t}|gdWdn1s.0Y|t|jddS)Nr/z%got an invalid type in Constant: list)r@rCrr>rr)r0rrrrtest_validations  , zConstantTests.test_validationc Cs^dddtdtfD]F}|j|d&||}|||Wdq1sN0YqdS)NFTr )const)rrr^rr)r0rr9rrrtest_singletonss zConstantTests.test_singletonsc Csd}tdh}tdD]}|df}t|dh}qddddd td td ||f }|D]F}|j|d &||}|||WdqR1s0YqRdS) N)rrrr={g^@y^@unicodebytesrrr)rrrr^rr>)r0Z nested_tupleZnested_frozensetr?r7r9rrrr test_valuess    zConstantTests.test_valuescCstd}|jdjd}tjdd}t||||jdjd<|t}t|ddWdn1sn0Y| t |j ddS)Nx = 1rrrstringrPz6expression which can't be assigned to in Store context) r+rgrjtargetsrr r@rr_r>rr)r0rhtarget new_targetrrrrtest_assign_to_constants    * z%ConstantTests.test_assign_to_constantcCs td}|t|ddS)Nz'docstring' x = 1Z docstring)r+rgr>r!)r0rhrrrr"s z ConstantTests.test_get_docstringcCs:t|dd}g}t|D]}|jdkr||jq|S)NrfrPZ LOAD_CONST)r_disZget_instructionsopnamerZargval)r0rhcoconstsZinstrrrrget_load_consts   zConstantTests.get_load_constcCsgd}ddd|D}|d7}|tdft|}||||t|j|D]B\}}t |tj s|Jt |tj |d}t ||j||_qZ||||dS)N) NTF|g@y@rrr/rcSsg|]}d|qS)zx={!r})format)rrrrrr r z1ConstantTests.test_load_const..z x = ...r)rrrr+rgr>rr]rjrrfrrr r9)r0rrBrhrrrrrrtest_load_consts      zConstantTests.test_load_constcCsltd}|jdj}tjdd}t||j||_tjdd}t||j||_|t |ddS)Nz1 + 2r ry4@y$@4@) r+rgrjr9rr rrr>r)r0rhbinopZnew_leftZ new_rightrrrr4s    zConstantTests.test_literal_evalcCstjdddj}||jd||jdtjdddj}||jd||jdtjdddj}||jd||jdtjdddj}||jd ||jddS) Nz"x"rRr rEzu"x"rzr"x"zb"x"x)r+rgrjr>r9rV)r0rrrrtest_string_kindszConstantTests.test_string_kindN)rr.rHrrrrrrr"rrrrr4rrrrrrs  rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dS)?EndPositionTestszTests for end position of AST nodes. Testing end positions of nodes requires a bit of extra care because of how LL parsers work. cCs ||j|||j|dSry)r>r r)r0r8r rrrr_check_end_pos+szEndPositionTests._check_end_poscCs|t|||dSry)r>r+get_source_segment)r0rr8Zcontentrrr_check_content/szEndPositionTests._check_contentcCst|jdjS)Nr)r+rgrjr9rrrr _parse_value2szEndPositionTests._parse_valuecCsJd}||}|||jd|||jjdd|||jjddS)Nzlambda x, *y: NonerrrErU)rrrjrrB)r0rZlamrrrr7s  zEndPositionTests.test_lambdacCstd}t|jd}||dd|||jdd|||jjdd|||jjdjd|||jj d|||jj jd dS) Nz def func(x: int, *args: str, z: float = 0, **kwargs: Any) -> bool: return True rrz return Truezx: intrz kwargs: AnyAny) rrvr+rgrjrrr annotationrr0rZfdefrrr test_func_def>s zEndPositionTests.test_func_defcCsNd}||}|||jd|||jdjd|||jdjddS)Nzfunc(x, y=2, **kw)rr2rkw)rrrrr9r0rrrrrrNs  zEndPositionTests.test_callcCs0d}||}|||jd||dddS)Nzx[0]()zx[0]rr1)rrrrrrrrtest_call_noargsUs z!EndPositionTests.test_call_noargscCsVtd}t|jd}||dd|||jdd|||jdddS)Nz? class C(A, B): x: int = 0 rr=rBz x: int = 0)rrvr+rgrjrrr^r0rcdefrrrtest_class_def[s  zEndPositionTests.test_class_defcCs.d}t|jd}|||jdjddS)Nz$class S(metaclass=abc.ABCMeta): passrz abc.ABCMeta)r+rgrjrrr9rrrr test_class_kweszEndPositionTests.test_class_kwcCs>td}t|jd}||dd||jdddS)Nzh x = """Some multi-line text. It goes on starting from same indent.""" rr(rrvr+rgrjrr9r0rrrrrtest_multi_line_strjs z$EndPositionTests.test_multi_line_strcCs>td}t|jd}||dd||jdddS)NzB x = "first part" \ "second part" rr=r'rrrrrtest_continued_strts z#EndPositionTests.test_continued_strcCstd}t|}|jd}|jd}|jd}|jd}|jd}||dd||dd ||d d ||d d||d d|||jd |||jdd|||jdjd|||j d|||jdd|||j dj ddS)Na while True: pass if one(): x = None elif other(): y = None else: z = None for x, y in stuff: assert True try: raise RuntimeError except TypeError as e: pass pass rrr=rrrr% rrzx = Nonezother()x, yzraise RuntimeErrorrC) rrvr+rgrjrrrr*rhandlersr-)r0rrwZ while_loopZif_stmtZfor_loopZtry_stmtZ pass_stmtrrr test_suites}s$       zEndPositionTests.test_suitescCs,d}||}|jdj}|||ddS)Nzx = f"abc {x + y} abc"rzx + y)rr7r9rr0rZfstrrrrr test_fstrings  zEndPositionTests.test_fstringcCsTtd}||}|jdj}||dd|||jd|||jddS)Nz f"""Some multi-line text. { arg_one + arg_two } It goes on...""" rrrZarg_oneZarg_two) rrvrr7r9rrrrr rrrtest_fstring_multi_lines   z(EndPositionTests.test_fstring_multi_linecCs.td}t|jd}||dddS)NzT from x.y.z import ( a, b, c as c ) rrr)rrvr+rgrjr)r0rr{rrrtest_import_from_multi_lines z,EndPositionTests.test_import_from_multi_linecCsd}d}td}t|j|||f\}}}|||jd|||jjd|||jjd|||jjd|||jj djd |||jj d jd | |d d dS) Nz f()[1, 2] [0]z x[ a.b: c.d]zN x[ a.b: f () , g () : c.d ] z f()[1, 2]z1, 2r'zc.drf ()rg ()r) rrvmaprrr9rkrmrleltsr)r0s1s2smZi1Zi2rqrrr test_slicess zEndPositionTests.test_slicescCsZtd}||}||dd|||jd|||jd|||jjddS)NzF (1 * 2 + (3 ) + 4 ) r=r14z 1 * 2 + (3 )3)rrvrrrrr)r0rrrrr test_binops   zEndPositionTests.test_binopcCsDtd}t|jdj}||dd|||jdddS)Nz{ if (one_condition and (other_condition or yet_another_one)): pass rr=,rz"other_condition or yet_another_one) rrvr+rgrjrrrr7)r0rZboprrrrs  zEndPositionTests.test_boolopc Cspd}d}d}td}t|j||||f\}}}}|||d|||d|||d||dd dS) Nzx = () ;z x = 1 , ;zx = (1 , 2 ) ;z? x = ( a, b, ) r)z1 ,z(1 , 2 )rr)rrvrrrr) r0rrZs3rt1t2Zt3Ztmrrr test_tupless zEndPositionTests.test_tuplescCs4d}||}|||||||jdddS)Nz func(x. y .z)rzx. y .z)rrrrrrrtest_attribute_spacess z&EndPositionTests.test_attribute_spacescCsvd}t|jdj}|t|jd|||dd|}t|jdjj}|t|jd|||ddS)Nz( ( ( a + b ) ) )rrr$await )r+rgrjr9r>r-rr)r0rr(rrrrtest_redundant_parenthesissz+EndPositionTests.test_redundant_parenthesisc Csd}|D]\}}||~t|jdj}|t|j|||||d|}t|jdjj}|t|j|||||Wdq1s0YqdS)N))z( ( ( a ) ) ) ( )r )z( ( ( a ) ) ) ( b )r )z( ( ( a ) ) ) [ b ]r)z( ( ( a ) ) ) . brrr) r^r+rgrjr9r>r-rr)r0rrrr(rrrr(test_trailers_with_redundant_parenthesiss  z9EndPositionTests.test_trailers_with_redundant_parenthesiscCsd}d}||}||}|||jdd|||jdd|||jdd|||jdd |||jdd dS) Nz[{}, {1, }, {1, 2,} ]z{a: b, f (): g () ,}rr%rz{1, }r=z{1, 2,}rr)rrrr6r7)r0rrc1c2rrr test_displays s  zEndPositionTests.test_displayscCstd}||}||dd|||jdjd|||jjdjd|||jjdjdd|||jjdj ddS) Nza x = [{x for x, y in stuff if cond.x} for stuff in things] r=%rZthingsstuffzcond.xr) rrvrrr generatorsitereltifsr)r0rcmprrrtest_comprehensions+s  z$EndPositionTests.test_comprehensionscCsLtd}t|jd}|||jdjd|||jdjddS)NzT async def f(): yield x await y rzyield xrzawait y)rrvr+rgrjrr9rrrrtest_yield_await7s z!EndPositionTests.test_yield_awaitcCs<td}td}||}|t||j|dS)NzD x = ( a, b, ) + () z; ( a, b, ) )rrvrr>r+rr)r0s_origZs_tuplerrrrtest_source_segment_multiAs   z*EndPositionTests.test_source_segment_multicCsBtd}d}t|jd}|tj||jddd|dS)Nuf class C: def fun(self) -> None: "ЖЖЖЖЖ" u/ def fun(self) -> None: "ЖЖЖЖЖ"rTZpaddedrrvr+rgrjr>r)r0r.s_methodrrrrtest_source_segment_paddedOs  z+EndPositionTests.test_source_segment_paddedcCsdd}t|j\}}}}}|||d|||d|||d|||d|||ddS)Nz!v = 1 w = 1 x = 1 y = 1 z = 1 r zw = 1rzy = 1zz = 1)r+rgrjr)r0rr(rrErUrrrrtest_source_segment_endings[sz,EndPositionTests.test_source_segment_endingscCsBtd}d}t|jd}|tj||jddd|dS)Nzb class C: def fun(self) -> None: pass z+ def fun(self) -> None: passrTr0r1)r0rr2rrrrtest_source_segment_tabsds z)EndPositionTests.test_source_segment_tabscCstd}t|j\}}}}|`|`|`|`|t|||t|||t|||t||dS)Nzv = 1 w = 1 x = 1 y = 1 ) r+rgrjr r r rrNr)r0rr(rrErUrrr test_source_segment_missing_infopsz1EndPositionTests.test_source_segment_missing_infoN)"rr.rHrrrrrrrrrrrrr r r rrrrrrr r!r$r,r-r/r3r4r5r6rrrrr%s>   ,          rc@seZdZddZdS)NodeVisitorTestscsGfdddtj}ttd}|}gtjdd(}tddt||Wdn1sh0Y| gd| d d |Dgd dS) NcsHeZdZfddZfddZfddZfddZfd d Zd S) z9NodeVisitorTests.test_old_constant_nodes..Visitorcs|jd|jfdS)Nr)rr rrlogrr visit_NumszCNodeVisitorTests.test_old_constant_nodes..Visitor.visit_Numcs|jd|jfdS)Nrrr rrr8rr visit_StrszCNodeVisitorTests.test_old_constant_nodes..Visitor.visit_Strcs|jd|jfdS)Nrr;rr8rr visit_BytesszENodeVisitorTests.test_old_constant_nodes..Visitor.visit_Bytescs|jd|jfdS)Nr)rr r9rr8rrvisit_NameConstantszLNodeVisitorTests.test_old_constant_nodes..Visitor.visit_NameConstantcs|jddfdS)Nr.)rr rr8rrvisit_EllipsisszHNodeVisitorTests.test_old_constant_nodes..Visitor.visit_EllipsisN)rr.rHr:r<r=r>r?rr8rrVisitor~s     r@z i = 42 f = 4.25 c = 4.25j s = 'string' b = b'bytes' t = True n = None e = ... T)recordalwaysr#))rrr;)r=rr)rrr)rrr)rrr)r1rT)rrN)rr.cSsg|]}t|jqSr)rmessage)rrrrrr r z.)+visit_Num is deprecated; add visit_ConstantrDrDz+visit_Str is deprecated; add visit_Constantz-visit_Bytes is deprecated; add visit_Constant4visit_NameConstant is deprecated; add visit_ConstantrEz0visit_Ellipsis is deprecated; add visit_Constant) r+Z NodeVisitorrgrwarningscatch_warningsfilterwarningsDeprecationWarningZvisitr>)r0r@rwZvisitorZwlogrr8rtest_old_constant_nodes}s  ( z(NodeVisitorTests.test_old_constant_nodesN)rr.rHrJrrrrr7|sr7c@s,eZdZddZddZddZddZd S) ModuleStateTestscCs<d}d}d}t|||tjd}t|||}||tjdS)Nzx + 1rfrR)flags)r_r+r`rttypesCodeType)r0rBfilenamer rdrrrcheck_ast_modules  z!ModuleStateTests.check_ast_modulecCspttjdd8tjd=ddl}tjd=ddl}|Wdn1sN0Y~~t|dS)N_astr)r swap_itemsysmodulesrQrPrM)r0Zast1rrrrtest_reload_modules&z#ModuleStateTests.test_reload_modulec stfdd}ttjddptjd=ttd|:||dtjddl }| |Wdn1sz0YWdn1s0YdS)Ncstj|<Sry)rSrT)r1rrZlazy_modrr my_imports z4ModuleStateTests.test_sys_modules..my_importrQ __import__r) objectrrRrSrTrbuiltinsrPZ assertNotInrQr)r0rWrQrrVrtest_sys_moduless z!ModuleStateTests.test_sys_modulescCs"td}t|}||ddS)Nap import _ast import ast import gc import sys import types # Create _ast.AST subclasses instances and call PyAST_Check() ast_tree = compile('x+1', '', 'eval', flags=ast.PyCF_ONLY_AST) code = compile(ast_tree, 'string', 'eval') if not isinstance(code, types.CodeType): raise AssertionError # Unloading the _ast module must not crash. del ast, _ast del sys.modules['ast'], sys.modules['_ast'] gc.collect() r)rrZrun_in_subinterpr>)r0rBresrrrtest_subinterpreters z$ModuleStateTests.test_subinterpreterN)rr.rHrPrUr[r]rrrrrKs rKcCstdkr dStjdddgkrtdftdftdffD]F\}}t|d|D]$}t|d|}td t |fqNtd q6td t t dS) N__main__rz-grPrQrRz _results = [rUz%r,]zmain()) rrSargvrWrYr[printr+rgr SystemExitunittestmain)Z statementsrVZ statementrhrrrrds    rdr)rrrrrrreNN)rrrr)rrgzmodule docstringNrZ)rrrr'rr)r[)rr%rr')rrr)rrr%rri)rrjzfunction docstringN)rrrrrVrr1rrrJNN)r[)rrrr)rrr)rrrrr%rN)r[)rrrrmrg)rVrrrr&rNN)r[)rrrrh)rrr)rVrrrrrNN)r[)rrrrp)rrrG)rk)rVrr%rrrNN)rVrrrrrNN)rVrrrrNN)rV)rrrirNN)rVr#r'rNN)rV)r)rr;rNN)r)r+r-r;N)rV)r1r7rNN)rrr&rrrN)rrrmrNNr)rrrr8)rr )rr:rrr)rrz doc for f()Nr])rrrrC)r[)rrrr)rrrr)rrr%rr)rrzdocstring for class CN)r}rqrYr)ZReturnrrrrm)rrrrrmrNrcrrrr)r}rrrrr()ZDelrfr}rrrrr(rR)rrrNrrrrrrrrr)r}rrJr)r}rr=rrrrr)r}rlrr)rrrr%r}rrrr=rJr)r}rrrrrr)r}rnrr)rhrrrr1rr)rrrrr1rNr|)rrrr)r}rr(r)r}rsr(r)r[)rr&rrrl)r}rlr(rrn)r}rr(r)r[)rrrr%)rrrr1)r}rrJr)r[)r=r=r=r1)rrrr1)r})rrrr1rr)r[)rr=rr1)rrr1r1)rrr1r1)r[)r1r=r1r1rp)rrrr)r)r}rrEr)r}rrrr&rUr)r[)rr'rr)rrr)r)r}rr'rrrr)r}rrhrrqr)r[)rrprrrr )rr1rr)r})rr1rrrr)r)rrmrrrNrtru)r}rrrrmrr)rwrrrr)r}rrrrr(rNry)rrrr)r@rSNrurS)r@r(Nr}rr()rrrrrN)r[re)ZBreakrr&rrm)rrrr)ZContinue)rr&rr)rrrr)r}rrJr)r}rlrr)r}rrr)rrrr)rrrr%)r}rrJr)r}rrr)r}rrr)r[rr)rrr&rr)r=rr1r)r})rrrr1Aar)r})rrrr%Bbrr~)rrrr1)r})rrrr1rr)r})rrrr1rr)r})rrrrZCcr)rrr"rr}rrJr)r}rrr)r}rrr)r}rrmrrrEr)r}rurr)r})rrrwrjr)r})rrr!rr)rr&rr)r}rr(r)r}rrr)r}rrErr)r}rrrr)r}rrr)r}rrrr'rEr)r}rrrrhrr)rrrr)r}rsrr)r}rtrErZAsyncFunctionDef)rrrrh)rr=rr=r)rrzasync functionN)rrrrhZAwait)rrrrh)r}rZ somethingr)rrrrZAsyncFor)r=rrr)r})r=r&r=rrr)r})r=rmr=rrbr)rr=rr=r)rrrN)rrrrr)rrr=N)rrr=rpZ AsyncWith)r=rr=rp)r)r})r=rr=r'rJr)r})r=rr=rhrr)rr=rr=rp)rrrN)rrr=N)rrrr)rrlr=N)rrrNrr)rrrr)rr=rr)rrrN)rrrNr)r})r=r=r=rrbr)r})r=rr=rrr)r}rrrr)rrrr')r[)rr%rr')r}rrrr1Zdeco1r)r=rr=r)r})r=rr=r1Zdeco2r)rrrr%)r})rrrr1Zdeco3r)rrrN)rrrr)r[)rrrr)r=rr=r')r[)r=r%r=r')rrrr)r}rrrrZdecor)rrrr)r}rlrJr)r}rrJr)r}rrr)rr)r)rrrrrrrrr)rr)Z NamedExpr)rrrrr)rrlrN)rrrr)rVrrNN)rVrrNN)rVrrNN)r[)rrvrrr)rVrrNN)rVrrprrvrNN)r[)rrrri)rrrrz)rV)rrrrrNN)r[rxrrnrN)rVrtrNN)rV)rrrrrNN)rrrr=N)rrrN)rVrurNN)r)rrrrrNr)r[)rrwrr)rrrr)r[)rrrr)rrrr;)rV)rrirryrNN)r[)r&rr;)rrrr)rV)rrrrrNN)r[)r$rrrQ)rr)rrrrrrr=N)rrfrr)rr}rrJr)r}rlrr)r)rrrrr}rrr)r)rGr)rH)r}rr(rr)rrrr&)rroNNrrrNrrr=Nrrrr=)rrNN)rrrr1)r)r=r1r=rrN)r)rrrr&r=N)r}rrr)r}rrrr)r}rrJrr)r}rrJr)r}rrr)r}rrr)rrrrvr)r}rtrr)r})rrrrprrrr)ZLtrrnrN)r}rrr)rr)r)rrrr)r}rrrr)ra)rr1rr%rr)ra)rr'rrmN)r}rrr)rr=rr%)rrrr%)rrrN)rrrN)rrrr)r}rnrJr)r}rrr)r)rrrN)r)rrrN)rrrrrr)r)rrr)r)rr=rr)r}rrr)r}rrrNr)r)r}rr(r))rrrN)rrr=N)rrrN)rr)rrrN)rr)rrrrrrr)rr)r)rrrr&)r}rnrJrrr)r)rrrr)rrrN)rrtr=NNr)r+rZrrrSrMrcrFrKtextwraprrrrrWrYr[ZTestCaser*rrMrrr7rrKrdrXrZr\rrrrs   K2p Y2Q  ,,.0,,L,""" $&&   &&&<42&0D>:,,FHH6N. .28806888<F &""@BB@BB@BB&"22%