ยปCore Development>Code coverage>Lib/lib2to3/fixes/fix_intern.py

# Python code coverage for Lib/lib2to3/fixes/fix_intern.py

#countcontent
2n/a# Licensed to PSF under a Contributor Agreement.
3n/a
4n/a"""Fixer for intern().
5n/a
6n/aintern(s) -> sys.intern(s)"""
7n/a
8n/a# Local imports
9n/afrom .. import fixer_base
10n/afrom ..fixer_util import ImportAndCall, touch_import
11n/a
12n/a
13n/aclass FixIntern(fixer_base.BaseFix):
14n/a BM_compatible = True
15n/a order = "pre"
16n/a
17n/a PATTERN = """
18n/a power< 'intern'
19n/a trailer< lpar='('
20n/a ( not(arglist | argument<any '=' any>) obj=any
21n/a | obj=arglist<(not argument<any '=' any>) any ','> )
22n/a rpar=')' >
23n/a after=any*
24n/a >
25n/a """
26n/a
27n/a def transform(self, node, results):
28n/a if results:
29n/a # I feel like we should be able to express this logic in the
30n/a # PATTERN above but I don't know how to do it so...
31n/a obj = results['obj']
32n/a if obj:
33n/a if obj.type == self.syms.star_expr:
34n/a return # Make no change.
35n/a if (obj.type == self.syms.argument and
36n/a obj.children[0].value == '**'):
37n/a return # Make no change.
38n/a names = ('sys', 'intern')
39n/a new = ImportAndCall(node, results, names)
40n/a touch_import(None, 'sys', node)
41n/a return new