当前位置: 首页>>代码示例>>Python>>正文


Python FuncDef.name方法代码示例

本文整理汇总了Python中mypy.nodes.FuncDef.name方法的典型用法代码示例。如果您正苦于以下问题:Python FuncDef.name方法的具体用法?Python FuncDef.name怎么用?Python FuncDef.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mypy.nodes.FuncDef的用法示例。


在下文中一共展示了FuncDef.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
 def visit_func_def(self, func: FuncDef) -> None:
     sem = self.sem
     if sem.type is not None:
         # Don't process methods during pass 1.
         return
     func.is_conditional = sem.block_depth[-1] > 0
     func._fullname = sem.qualified_name(func.name())
     at_module = sem.is_module_scope()
     if at_module and func.name() in sem.globals:
         # Already defined in this module.
         original_sym = sem.globals[func.name()]
         if (original_sym.kind == UNBOUND_IMPORTED or
                 isinstance(original_sym.node, ImportedName)):
             # Ah this is an imported name. We can't resolve them now, so we'll postpone
             # this until the main phase of semantic analysis.
             return
         if not sem.set_original_def(original_sym.node, func):
             # Report error.
             sem.check_no_global(func.name(), func)
     else:
         if at_module:
             sem.globals[func.name()] = SymbolTableNode(GDEF, func)
         # Also analyze the function body (needed in case there are unreachable
         # conditional imports).
         sem.function_stack.append(func)
         sem.scope.enter_function(func)
         sem.enter()
         func.body.accept(self)
         sem.leave()
         sem.scope.leave()
         sem.function_stack.pop()
开发者ID:sixolet,项目名称:mypy,代码行数:33,代码来源:semanal_pass1.py

示例2: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
 def visit_func_def(self, o: FuncDef) -> None:
     if self.is_private_name(o.name()):
         return
     if self.is_not_in_all(o.name()):
         return
     if self.is_recorded_name(o.name()):
         return
     if not self._indent and self._state not in (EMPTY, FUNC):
         self.add('\n')
     if not self.is_top_level():
         self_inits = find_self_initializers(o)
         for init in self_inits:
             init_code = self.get_init(init)
             if init_code:
                 self.add(init_code)
     self.add("%sdef %s(" % (self._indent, o.name()))
     self.record_name(o.name())
     args = []  # type: List[str]
     for i, arg_ in enumerate(o.arguments):
         var = arg_.variable
         kind = arg_.kind
         name = var.name()
         init_stmt = arg_.initialization_statement
         if init_stmt:
             if kind == ARG_NAMED and '*' not in args:
                 args.append('*')
             arg = '%s=' % name
             rvalue = init_stmt.rvalue
             if isinstance(rvalue, IntExpr):
                 arg += str(rvalue.value)
             elif isinstance(rvalue, StrExpr):
                 arg += "''"
             elif isinstance(rvalue, BytesExpr):
                 arg += "b''"
             elif isinstance(rvalue, FloatExpr):
                 arg += "0.0"
             elif isinstance(rvalue, UnaryExpr) and isinstance(rvalue.expr, IntExpr):
                 arg += '-%s' % rvalue.expr.value
             elif isinstance(rvalue, NameExpr) and rvalue.name in ('None', 'True', 'False'):
                 arg += rvalue.name
             else:
                 arg += '...'
         elif kind == ARG_STAR:
             arg = '*%s' % name
         elif kind == ARG_STAR2:
             arg = '**%s' % name
         else:
             arg = name
         args.append(arg)
     self.add(', '.join(args))
     self.add("): ...\n")
     self._state = FUNC
开发者ID:axitkhurana,项目名称:mypy,代码行数:54,代码来源:stubgen.py

示例3: set_callable_name

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
def set_callable_name(sig: Type, fdef: FuncDef) -> Type:
    if isinstance(sig, FunctionLike):
        if fdef.info:
            if fdef.info.fullname() in TPDICT_FB_NAMES:
                # Avoid exposing the internal _TypedDict name.
                class_name = 'TypedDict'
            else:
                class_name = fdef.info.name()
            return sig.with_name(
                '{} of {}'.format(fdef.name(), class_name))
        else:
            return sig.with_name(fdef.name())
    else:
        return sig
开发者ID:python,项目名称:mypy,代码行数:16,代码来源:semanal_shared.py

示例4: enter_function_scope

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
 def enter_function_scope(self, fdef: FuncDef) -> str:
     """Enter a function target scope."""
     target = '%s.%s' % (self.full_target_stack[-1], fdef.name())
     self.target_stack.append(target)
     self.full_target_stack.append(target)
     self.scope_stack.append(fdef)
     return target
开发者ID:greatmazinger,项目名称:mypy,代码行数:9,代码来源:deps.py

示例5: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
 def visit_func_def(self, fdef: FuncDef) -> None:
     if not self.recurse_into_functions:
         return
     self.errors.push_function(fdef.name())
     self.analyze(fdef.type, fdef)
     super().visit_func_def(fdef)
     self.errors.pop_function()
开发者ID:greatmazinger,项目名称:mypy,代码行数:9,代码来源:semanal_pass3.py

示例6: visit_FunctionDef

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def visit_FunctionDef(self, n: ast35.FunctionDef) -> Node:
        args = self.transform_args(n.args, n.lineno)

        arg_kinds = [arg.kind for arg in args]
        arg_names = [arg.variable.name() for arg in args]
        arg_types = None  # type: List[Type]
        if n.type_comment is not None:
            try:
                func_type_ast = ast35.parse(n.type_comment, '<func_type>', 'func_type')
            except SyntaxError:
                raise TypeCommentParseError(TYPE_COMMENT_SYNTAX_ERROR, n.lineno)
            assert isinstance(func_type_ast, ast35.FunctionType)
            # for ellipsis arg
            if (len(func_type_ast.argtypes) == 1 and
                    isinstance(func_type_ast.argtypes[0], ast35.Ellipsis)):
                arg_types = [a.type_annotation if a.type_annotation is not None else AnyType()
                             for a in args]
            else:
                arg_types = [a if a is not None else AnyType() for
                            a in TypeConverter(line=n.lineno).visit_list(func_type_ast.argtypes)]
            return_type = TypeConverter(line=n.lineno).visit(func_type_ast.returns)

            # add implicit self type
            if self.in_class() and len(arg_types) < len(args):
                arg_types.insert(0, AnyType())
        else:
            arg_types = [a.type_annotation for a in args]
            return_type = TypeConverter(line=n.lineno).visit(n.returns)

        if isinstance(return_type, UnboundType):
            return_type.is_ret_type = True

        func_type = None
        if any(arg_types) or return_type:
            func_type = CallableType([a if a is not None else AnyType() for a in arg_types],
                                     arg_kinds,
                                     arg_names,
                                     return_type if return_type is not None else AnyType(),
                                     None)

        func_def = FuncDef(n.name,
                       args,
                       self.as_block(n.body, n.lineno),
                       func_type)
        if func_type is not None:
            func_type.definition = func_def
            func_type.line = n.lineno

        if n.decorator_list:
            var = Var(func_def.name())
            var.is_ready = False
            var.set_line(n.decorator_list[0].lineno)

            func_def.is_decorated = True
            func_def.set_line(n.lineno + len(n.decorator_list))
            func_def.body.set_line(func_def.get_line())
            return Decorator(func_def, self.visit_list(n.decorator_list), var)
        else:
            return func_def
开发者ID:danielfranca,项目名称:mypy,代码行数:61,代码来源:fastparse.py

示例7: transform_method

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def transform_method(self, fdef: FuncDef) -> List[FuncDef]:
        """Transform a method.

        The result is one or more methods.
        """
        # Transform the body of the method.
        self.tf.transform_function_body(fdef)
        
        res = Undefined # type: List[FuncDef]
        
        if fdef.is_constructor():
            # The method is a constructor. Constructors are transformed to one
            # method.
            res = [self.transform_method_implementation(fdef, fdef.name())]
        else:
            # Normal methods are transformed to 1-3 variants. The
            # first is the main implementation of the method, and the
            # second is the dynamically-typed wrapper. The third
            # variant is for method overrides, and represents the
            # overridden supertype method.
            
            res = [self.transform_method_implementation(
                fdef, fdef.name() + self.tf.type_suffix(fdef))]
            
            if fdef.info.bases and fdef.info.mro[1].has_method(fdef.name()):
                # Override.
                # TODO do not assume single inheritance
                
                # Is is an override with a different signature? For
                # trivial overrides we can inherit wrappers.
                if not is_simple_override(fdef, fdef.info):
                    # Create a wrapper for overridden superclass method.
                    res.append(self.override_method_wrapper(fdef))
                    # Create a dynamically-typed method wrapper.
                    res.append(self.dynamic_method_wrapper(fdef))
            else:
                # Not an override.
                
                # Create a dynamically-typed method wrapper.
                res.append(self.dynamic_method_wrapper(fdef))
        
        return res
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:44,代码来源:transformfunc.py

示例8: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def visit_func_def(self, fdef: FuncDef) -> int:
        if fdef.name().endswith("*"):
            # Wrapper functions are not supported yet.
            return -1

        self.enter()

        for arg in fdef.args:
            self.add_local(arg)
        fdef.body.accept(self)
        self.add_implicit_return(cast(Callable, fdef.type))

        if fdef.info:
            name = "%s.%s" % (fdef.info.name(), fdef.name())
        else:
            name = fdef.name()

        self.generated[name] = FuncIcode(len(fdef.args), self.blocks, self.register_types)

        self.leave()

        return -1
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:24,代码来源:icode.py

示例9: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def visit_func_def(self, o: FuncDef) -> None:
        if self.is_private_name(o.name()):
            return
        if self.is_not_in_all(o.name()):
            return
        if self.is_recorded_name(o.name()):
            return
        if not self._indent and self._state not in (EMPTY, FUNC):
            self.add('\n')
        if not self.is_top_level():
            self_inits = find_self_initializers(o)
            for init, value in self_inits:
                init_code = self.get_init(init, value)
                if init_code:
                    self.add(init_code)
        self.add("%sdef %s(" % (self._indent, o.name()))
        self.record_name(o.name())
        args = []  # type: List[str]
        for i, arg_ in enumerate(o.arguments):
            var = arg_.variable
            kind = arg_.kind
            name = var.name()
            annotated_type = o.type.arg_types[i] if isinstance(o.type, CallableType) else None
            if annotated_type and not (
                    i == 0 and name == 'self' and isinstance(annotated_type, AnyType)):
                annotation = ": {}".format(self.print_annotation(annotated_type))
            else:
                annotation = ""
            if arg_.initializer:
                initializer = '...'
                if kind in (ARG_NAMED, ARG_NAMED_OPT) and not any(arg.startswith('*')
                                                                  for arg in args):
                    args.append('*')
                if not annotation:
                    typename = self.get_str_type_of_node(arg_.initializer, True)
                    annotation = ': {} = ...'.format(typename)
                else:
                    annotation += '={}'.format(initializer)
                arg = name + annotation
            elif kind == ARG_STAR:
                arg = '*%s%s' % (name, annotation)
            elif kind == ARG_STAR2:
                arg = '**%s%s' % (name, annotation)
            else:
                arg = name + annotation
            args.append(arg)
        retname = None
        if isinstance(o.type, CallableType):
            retname = self.print_annotation(o.type.ret_type)
        elif o.name() == '__init__' or not has_return_statement(o):
            retname = 'None'
        retfield = ''
        if retname is not None:
            retfield = ' -> ' + retname

        self.add(', '.join(args))
        self.add("){}: ...\n".format(retfield))
        self._state = FUNC
开发者ID:sixolet,项目名称:mypy,代码行数:60,代码来源:stubgen.py

示例10: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
 def visit_func_def(self, node: FuncDef) -> None:
     old_global_scope = self.is_global_scope
     self.is_global_scope = False
     super().visit_func_def(node)
     self.is_global_scope = old_global_scope
     file_node = self.cur_mod_node
     if (self.is_global_scope
             and file_node.is_stub
             and node.name() == '__getattr__'
             and file_node.is_package_init_file()):
         # __init__.pyi with __getattr__ means that any submodules are assumed
         # to exist, even if there is no stub. Note that we can't verify that the
         # return type is compatible, since we haven't bound types yet.
         file_node.is_partial_stub_package = True
开发者ID:Michael0x2a,项目名称:mypy,代码行数:16,代码来源:semanal_pass1.py

示例11: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
 def visit_func_def(self, o: FuncDef) -> None:
     self.scope.enter_function(o)
     target = self.scope.current_target()
     if o.type:
         if self.is_class and isinstance(o.type, FunctionLike):
             signature = bind_self(o.type)  # type: Type
         else:
             signature = o.type
         for trigger in self.get_type_triggers(signature):
             self.add_dependency(trigger)
             self.add_dependency(trigger, target=make_trigger(target))
     if o.info:
         for base in non_trivial_bases(o.info):
             # Base class __init__/__new__ doesn't generate a logical
             # dependency since the override can be incompatible.
             if not self.use_logical_deps() or o.name() not in ('__init__', '__new__'):
                 self.add_dependency(make_trigger(base.fullname() + '.' + o.name()))
     self.add_type_alias_deps(self.scope.current_target())
     super().visit_func_def(o)
     variants = set(o.expanded) - {o}
     for ex in variants:
         if isinstance(ex, FuncDef):
             super().visit_func_def(ex)
     self.scope.leave()
开发者ID:Michael0x2a,项目名称:mypy,代码行数:26,代码来源:deps.py

示例12: method_wrapper

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def method_wrapper(self, act_as_func_def: FuncDef,
                       target_func_def: FuncDef, is_dynamic: bool,
                       is_wrapper_class: bool) -> FuncDef:
        """Construct a method wrapper.

        It acts as a specific method (with the same signature), coerces
        arguments, calls the target method and finally coerces the return
        value.
        """
        is_override = act_as_func_def.info != target_func_def.info
        
        # Determine suffixes.
        target_suffix = self.tf.type_suffix(target_func_def)
        wrapper_suffix = self.get_wrapper_suffix(act_as_func_def, is_dynamic)
        
        # Determine function signatures.
        target_sig = self.get_target_sig(act_as_func_def, target_func_def,
                                         is_dynamic, is_wrapper_class)
        wrapper_sig = self.get_wrapper_sig(act_as_func_def, is_dynamic)
        call_sig = self.get_call_sig(act_as_func_def, target_func_def.info,
                                     is_dynamic, is_wrapper_class, is_override)
        
        if is_wrapper_class:
            bound_sig = cast(Callable,
                             translate_type_vars_to_bound_vars(target_sig))
        else:
            bound_sig = None
        
        call_stmt = self.call_wrapper(act_as_func_def, is_dynamic,
                                      is_wrapper_class, target_sig, call_sig,
                                      target_suffix, bound_sig)
        
        wrapper_args = self.get_wrapper_args(act_as_func_def, is_dynamic)    
        wrapper_func_def = FuncDef(act_as_func_def.name() + wrapper_suffix,
                                   wrapper_args,
                                   act_as_func_def.arg_kinds,
                                   [None] * len(wrapper_args),
                                   Block([call_stmt]),
                                   wrapper_sig)
        
        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
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:48,代码来源:transformfunc.py

示例13: type_suffix

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def type_suffix(self, fdef: FuncDef, info: TypeInfo = None) -> str:
        """Return the suffix for a mangled name.

        This includes an optional type suffix for a function or method.
        """
        if not info:
            info = fdef.info
        # If info is None, we have a global function => no suffix. Also if the
        # method is not an override, we need no suffix.
        if not info or (not info.bases or not info.bases[0].type.has_method(fdef.name())):
            return ""
        elif is_simple_override(fdef, info):
            return self.type_suffix(fdef, info.bases[0].type)
        elif self.is_pretty:
            return "`" + info.name()
        else:
            return "__" + info.name()
开发者ID:ashleyh,项目名称:mypy,代码行数:19,代码来源:transform.py

示例14: visit_func_def

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def visit_func_def(self, node: FuncDef) -> FuncDef:
        # Note that a FuncDef must be transformed to a FuncDef.
        new = FuncDef(node.name(),
                      [self.copy_argument(arg) for arg in node.arguments],
                      self.block(node.body),
                      cast(FunctionLike, self.optional_type(node.type)))

        self.copy_function_attributes(new, node)

        new._fullname = node._fullname
        new.is_decorated = node.is_decorated
        new.is_conditional = node.is_conditional
        new.is_abstract = node.is_abstract
        new.is_static = node.is_static
        new.is_class = node.is_class
        new.is_property = node.is_property
        new.original_def = node.original_def
        return new
开发者ID:the-gigi,项目名称:mypy,代码行数:20,代码来源:treetransform.py

示例15: visit_FunctionDef

# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import name [as 别名]
    def visit_FunctionDef(self, n):
        args = self.transform_args(n.args, n.lineno)

        arg_kinds = [arg.kind for arg in args]
        arg_names = [arg.variable.name() for arg in args]
        if n.type_comment is not None:
            func_type_ast = typed_ast.parse(n.type_comment, '<func_type>', 'func_type')
            arg_types = [a if a is not None else AnyType() for
                         a in TypeConverter(line=n.lineno).visit(func_type_ast.argtypes)]
            return_type = TypeConverter(line=n.lineno).visit(func_type_ast.returns)

            # add implicit self type
            if self.in_class and len(arg_types) < len(args):
                arg_types.insert(0, AnyType())
        else:
            arg_types = [a.type_annotation for a in args]
            return_type = TypeConverter(line=n.lineno).visit(n.returns)

        func_type = None
        if any(arg_types) or return_type:
            func_type = CallableType([a if a is not None else AnyType() for a in arg_types],
                                     arg_kinds,
                                     arg_names,
                                     return_type if return_type is not None else AnyType(),
                                     None)

        func_def = FuncDef(n.name,
                       args,
                       self.as_block(n.body, n.lineno),
                       func_type)
        if func_type is not None:
            func_type.definition = func_def

        if n.decorator_list:
            var = Var(func_def.name())
            var.is_ready = False
            var.set_line(n.decorator_list[0].lineno)

            func_def.is_decorated = True
            func_def.set_line(n.lineno + len(n.decorator_list))
            func_def.body.set_line(func_def.get_line())
            return Decorator(func_def, self.visit(n.decorator_list), var)
        else:
            return func_def
开发者ID:allthedata,项目名称:mypy,代码行数:46,代码来源:fastparse.py


注:本文中的mypy.nodes.FuncDef.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。