Back to index

python3.2  3.2.2
Classes | Variables
lib2to3.fixes.fix_idioms Namespace Reference

Classes

class  FixIdioms

Variables

string CMP = "(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)"
string TYPE = "power< 'type' trailer< '(' x=any ')' > >"

Detailed Description

Adjust some old Python 2 idioms to their modern counterparts.

* Change some type comparisons to isinstance() calls:
    type(x) == T -> isinstance(x, T)
    type(x) is T -> isinstance(x, T)
    type(x) != T -> not isinstance(x, T)
    type(x) is not T -> not isinstance(x, T)

* Change "while 1:" into "while True:".

* Change both

    v = list(EXPR)
    v.sort()
    foo(v)

and the more general

    v = EXPR
    v.sort()
    foo(v)

into

    v = sorted(EXPR)
    foo(v)

Variable Documentation

string lib2to3.fixes.fix_idioms.CMP = "(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)"

Definition at line 34 of file fix_idioms.py.

string lib2to3.fixes.fix_idioms.TYPE = "power< 'type' trailer< '(' x=any ')' > >"

Definition at line 35 of file fix_idioms.py.