diff options
Diffstat (limited to 'Lib/lib2to3/fixes/fix_intern.py')
-rw-r--r-- | Lib/lib2to3/fixes/fix_intern.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/lib2to3/fixes/fix_intern.py b/Lib/lib2to3/fixes/fix_intern.py new file mode 100644 index 0000000..6d33f8c --- /dev/null +++ b/Lib/lib2to3/fixes/fix_intern.py @@ -0,0 +1,43 @@ +# Copyright 2006 Georg Brandl. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for intern(). + +intern(s) -> sys.intern(s)""" + +# Local imports +from .. import pytree +from . import basefix +from .util import Name, Attr + + +class FixIntern(basefix.BaseFix): + + PATTERN = """ + power< 'intern' + trailer< lpar='(' + ( not(arglist | argument<any '=' any>) obj=any + | obj=arglist<(not argument<any '=' any>) any ','> ) + rpar=')' > + after=any* + > + """ + + def transform(self, node, results): + syms = self.syms + obj = results["obj"].clone() + if obj.type == syms.arglist: + newarglist = obj.clone() + else: + newarglist = pytree.Node(syms.arglist, [obj.clone()]) + after = results["after"] + if after: + after = [n.clone() for n in after] + new = pytree.Node(syms.power, + Attr(Name("sys"), Name("intern")) + + [pytree.Node(syms.trailer, + [results["lpar"].clone(), + newarglist, + results["rpar"].clone()])] + after) + new.set_prefix(node.get_prefix()) + return new |