コード例 #1
0
ファイル: transformfunc.py プロジェクト: SRiikonen/mypy-py
 def get_target_sig(self, act_as_func_def, target_func_def, is_dynamic, is_wrapper_class):
     """Return the target method signature for a method wrapper."""
     sig = function_type(target_func_def)
     if is_wrapper_class:
         if sig.is_generic() and is_dynamic:
             sig = translate_function_type_vars_to_dynamic(sig)
         return translate_type_vars_to_wrapped_object_vars(sig)
     elif is_dynamic:
         if sig.is_generic():
             return translate_function_type_vars_to_dynamic(sig)
         else:
             return sig
     else:
         return sig
コード例 #2
0
 def get_target_sig(self, act_as_func_def: FuncDef,
                    target_func_def: FuncDef,
                    is_dynamic: bool, is_wrapper_class: bool) -> Callable:
     """Return the target method signature for a method wrapper."""
     sig = cast(Callable, function_type(target_func_def))
     if is_wrapper_class:
         if sig.is_generic() and is_dynamic:
             sig = cast(Callable,
                        translate_function_type_vars_to_dynamic(sig))
         return cast(Callable,
                     translate_type_vars_to_wrapped_object_vars(sig))
     elif is_dynamic:
         if sig.is_generic():
             return cast(Callable,
                         translate_function_type_vars_to_dynamic(sig))
         else:
             return sig
     else:
         return sig
コード例 #3
0
ファイル: transformfunc.py プロジェクト: prodigeni/mypy
    def get_call_sig(self, act_as_func_def: FuncDef, current_class: TypeInfo,
                     is_dynamic: bool, is_wrapper_class: bool,
                     is_override: bool) -> Callable:
        """Return the source signature in a wrapped call.

        It has type variables replaced with 'Any', but as an
        exception, type variables are intact in the return type in
        generic wrapper classes. The exception allows omitting an
        extra return value coercion, as the target return type and the
        source return type will be the same.
        """
        sig = cast(Callable, function_type(act_as_func_def))
        if is_dynamic:
            return dynamic_sig(sig)
        elif is_generic(act_as_func_def):
            call_sig = sig
            # If this is an override wrapper, keep type variables
            # intact. Otherwise replace them with dynamic to get
            # desired coercions that check argument types.
            if not is_override or is_wrapper_class:
                call_sig = (cast(Callable, replace_type_vars(call_sig, False)))
            else:
                call_sig = cast(
                    Callable,
                    map_type_from_supertype(call_sig, current_class,
                                            act_as_func_def.info))
            if is_wrapper_class:
                # Replace return type with the original return within
                # wrapper classes to get rid of an unnecessary
                # coercion. There will still be a coercion due to the
                # extra coercion generated for generic wrapper
                # classes. However, function generic type variables
                # still need to be replaced, as the wrapper does not
                # affect them.
                ret = sig.ret_type
                if is_dynamic:
                    ret = translate_function_type_vars_to_dynamic(ret)
                call_sig = replace_ret_type(
                    call_sig, translate_type_vars_to_wrapper_vars(ret))
            return call_sig
        else:
            return sig
コード例 #4
0
ファイル: transformfunc.py プロジェクト: FlorianLudwig/mypy
 def get_call_sig(self, act_as_func_def: FuncDef,
                  current_class: TypeInfo, is_dynamic: bool,
                  is_wrapper_class: bool, is_override: bool) -> Callable:
     """Return the source signature in a wrapped call.
     
     It has type variables replaced with 'Any', but as an
     exception, type variables are intact in the return type in
     generic wrapper classes. The exception allows omitting an
     extra return value coercion, as the target return type and the
     source return type will be the same.
     """
     sig = cast(Callable, function_type(act_as_func_def))
     if is_dynamic:
         return dynamic_sig(sig)
     elif is_generic(act_as_func_def):
         call_sig = sig
         # If this is an override wrapper, keep type variables
         # intact. Otherwise replace them with dynamic to get
         # desired coercions that check argument types.
         if not is_override or is_wrapper_class:
             call_sig = (cast(Callable, replace_type_vars(call_sig, False)))
         else:
             call_sig = cast(Callable, map_type_from_supertype(
                 call_sig, current_class, act_as_func_def.info))
         if is_wrapper_class:
             # Replace return type with the original return within
             # wrapper classes to get rid of an unnecessary
             # coercion. There will still be a coercion due to the
             # extra coercion generated for generic wrapper
             # classes. However, function generic type variables
             # still need to be replaced, as the wrapper does not
             # affect them.
             ret = sig.ret_type
             if is_dynamic:
                 ret = translate_function_type_vars_to_dynamic(ret)
             call_sig = replace_ret_type(
                 call_sig, translate_type_vars_to_wrapper_vars(ret))
         return call_sig
     else:
         return sig
コード例 #5
0
ファイル: transformfunc.py プロジェクト: SRiikonen/mypy
        
        self.tf.add_line_mapping(target_func_def, wrapper_func_def)
        
        if is_wrapper_class and not is_dynamic:
            self.tf.prepend_generic_function_tvar_args(wrapper_func_def)
        
        return wrapper_func_def
    
    Callable get_target_sig(self, FuncDef act_as_func_def,
                            FuncDef target_func_def,
                            bool is_dynamic, bool is_wrapper_class):
        """Return the target method signature for a method wrapper."""
        sig = (Callable)function_type(target_func_def)
        if is_wrapper_class:
            if sig.is_generic() and is_dynamic:
                sig = (Callable)translate_function_type_vars_to_dynamic(sig)
            return (Callable)translate_type_vars_to_wrapped_object_vars(sig)
        elif is_dynamic:
            if sig.is_generic():
                return (Callable)translate_function_type_vars_to_dynamic(sig)
            else:
                return sig
        else:
            return sig
    
    Callable get_wrapper_sig(self, FuncDef act_as_func_def, bool is_dynamic):
        """Return the signature of the wrapper method.

        The wrapper method signature has an additional type variable
        argument (with type 'any'), and all type variables have been
        erased.