o 0i8 @ sf d Z ddlmZ ddlmZ ddlmZmZmZm Z m Z ddlmZ ddlmZ G dd dejZd S ) a Fixer that changes map(F, ...) into list(map(F, ...)) unless there exists a 'from future_builtins import map' statement in the top-level namespace. As a special case, map(None, X) is changed into list(X). (This is necessary because the semantics are changed in this case -- the new map(None, X) is equivalent to [(x,) for x in X].) We avoid the transformation (except for the special case mentioned above) if the map() call is directly contained in iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or for V in <>:. NOTE: This is still not correct if the original code was depending on map(F, X, Y, ...) to go on until the longest argument is exhausted, substituting None for missing values -- like zip(), it now stops as soon as the shortest argument is exhausted. )token) fixer_base)NameArgListCallListCompin_special_context)python_symbols)Nodec @ s e Zd ZdZdZdZdd ZdS )FixMapTaL map_none=power< 'map' trailer< '(' arglist< 'None' ',' arg=any [','] > ')' > [extra_trailers=trailer*] > | map_lambda=power< 'map' trailer< '(' arglist< lambdef< 'lambda' (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any > ',' it=any > ')' > [extra_trailers=trailer*] > | power< 'map' args=trailer< '(' [any] ')' > [extra_trailers=trailer*] > zfuture_builtins.mapc C s | |rd S g }d|v r|d D ] }|| q|jjtjkr8| |d | }d|_t t d|g}nd|v rZt|d |d |d }ttj |g| dd }nkd |v rh|d }d|_nKd|v r|d }|jtjkr|jd jtjkr|jd jd jtjkr|jd jd jdkr| |d d S ttj t d| g}d|_t|rd S ttj t dt|gg| }d|_|j|_|S )NZextra_trailerszYou should use a for loop here listZ map_lambdaZxpfpit)prefixZmap_noneargargs Nonezjcannot convert map(None, ...) with multiple arguments because map() now truncates to the shortest sequencemap)Zshould_skipappendZcloneparenttypesymsZsimple_stmtZwarningr r r r r ZpowerZtrailerchildrenZarglistr NAMEvaluer r )selfZnodeZresultsZtrailerstnewr r!