symbian-qemu-0.9.1-12/python-win32-2.6.1/lib/lib2to3/fixes/fix_callable.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 # Copyright 2007 Google, Inc. All Rights Reserved.
       
     2 # Licensed to PSF under a Contributor Agreement.
       
     3 
       
     4 """Fixer for callable().
       
     5 
       
     6 This converts callable(obj) into hasattr(obj, '__call__')."""
       
     7 
       
     8 # Local imports
       
     9 from .. import pytree
       
    10 from .. import fixer_base
       
    11 from ..fixer_util import Call, Name, String
       
    12 
       
    13 class FixCallable(fixer_base.BaseFix):
       
    14 
       
    15     # Ignore callable(*args) or use of keywords.
       
    16     # Either could be a hint that the builtin callable() is not being used.
       
    17     PATTERN = """
       
    18     power< 'callable'
       
    19            trailer< lpar='('
       
    20                     ( not(arglist | argument<any '=' any>) func=any
       
    21                       | func=arglist<(not argument<any '=' any>) any ','> )
       
    22                     rpar=')' >
       
    23            after=any*
       
    24     >
       
    25     """
       
    26 
       
    27     def transform(self, node, results):
       
    28         func = results["func"]
       
    29 
       
    30         args = [func.clone(), String(', '), String("'__call__'")]
       
    31         return Call(Name("hasattr"), args, prefix=node.get_prefix())