some problems for an introductory python test

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Aug 12 21:24:34 EDT 2021


On 13/08/21 11:42 am, Cameron Simpson wrote:
> 2: It took me a while to see, but this is a type annotiation.

Interestingly, it seems to be parsed as a form of assignment with
a missing RHS.

 >>> from ast import parse, dump
 >>> dump(parse("if0: print('yes!')"))
"Module(body=[AnnAssign(target=Name(id='if0', ctx=Store()), 
annotation=Call(func=Name(id='print', ctx=Load()), 
args=[Constant(value='yes!', kind=None)], keywords=[]), value=None, 
simple=1)], type_ignores=[])"

"An annotated assignment without the assignment? Eeuurgh!"

-- 
Greg


More information about the Python-list mailing list