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


Python astroid.Module方法代码示例

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


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

示例1: visit_importfrom

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_importfrom(self, node):
        if node.modname == '__future__':
            for name, _ in node.names:
                if name == 'division':
                    self._future_division = True
                elif name == 'absolute_import':
                    self._future_absolute_import = True
        else:
            if not self._future_absolute_import:
                if self.linter.is_message_enabled('no-absolute-import'):
                    self.add_message('no-absolute-import', node=node)
                    self._future_absolute_import = True
            if not _is_conditional_import(node) and not node.level:
                self._warn_if_deprecated(node, node.modname, {x[0] for x in node.names})

        if node.names[0][0] == '*':
            if self.linter.is_message_enabled('import-star-module-level'):
                if not isinstance(node.scope(), astroid.Module):
                    self.add_message('import-star-module-level', node=node) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:21,代码来源:python3.py

示例2: visit_attribute

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_attribute(self, node):
        """Look for removed attributes"""
        if node.attrname == 'xreadlines':
            self.add_message('xreadlines-attribute', node=node)
            return

        exception_message = 'message'
        try:
            for inferred in node.expr.infer():
                if (isinstance(inferred, astroid.Instance) and
                        utils.inherit_from_std_ex(inferred)):
                    if node.attrname == exception_message:

                        # Exceptions with .message clearly defined are an exception
                        if exception_message in inferred.instance_attrs:
                            continue
                        self.add_message('exception-message-attribute', node=node)
                if isinstance(inferred, astroid.Module):
                    self._warn_if_deprecated(node, inferred.name, {node.attrname},
                                             report_on_modules=False)
        except astroid.InferenceError:
            return 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:24,代码来源:python3.py

示例3: visit_importfrom

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_importfrom(self, node):
        """triggered when a from statement is seen"""
        basename = node.modname
        imported_module = self._get_imported_module(node, basename)

        self._check_misplaced_future(node)
        self._check_deprecated_module(node, basename)
        self._check_wildcard_imports(node, imported_module)
        self._check_same_line_imports(node)
        self._check_reimport(node, basename=basename, level=node.level)

        if isinstance(node.parent, astroid.Module):
            # Allow imports nested
            self._check_position(node)
        if isinstance(node.scope(), astroid.Module):
            self._record_import(node, imported_module)
        if imported_module is None:
            return
        modnode = node.root()
        self._check_relative_import(modnode, node, imported_module, basename)

        for name, _ in node.names:
            if name != '*':
                self._add_imported_module(node, '%s.%s' % (imported_module.name, name)) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:26,代码来源:imports.py

示例4: visit_functiondef

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_functiondef(self, node):
        if not self.linter.is_message_enabled('wrong-import-position', node.fromlineno):
            return
        # If it is the first non import instruction of the module, record it.
        if self._first_non_import_node:
            return

        # Check if the node belongs to an `If` or a `Try` block. If they
        # contain imports, skip recording this node.
        if not isinstance(node.parent.scope(), astroid.Module):
            return

        root = node
        while not isinstance(root.parent, astroid.Module):
            root = root.parent

        if isinstance(root, (astroid.If, astroid.TryFinally, astroid.TryExcept)):
            if any(root.nodes_of_class((astroid.Import, astroid.ImportFrom))):
                return

        self._first_non_import_node = node 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:23,代码来源:imports.py

示例5: functiondef_node

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def functiondef_node(draw, name=None, annotated=False, returns=False):
    name = name or draw(valid_identifier())
    args = draw(arguments_node(annotated))
    body = []
    returns_node = astroid.Return()
    arg_node, arg_type_node = draw(hs.sampled_from(list(zip(args.args, args.annotations))))
    if returns:
        returns_node.postinit(arg_node)
    else:
        returns_node.postinit(const_node(None))
    body.append(returns_node)
    node = astroid.FunctionDef(name=name)
    node.parent = astroid.Module('Default', None)
    node.postinit(
        args,
        body,
        None,
        arg_type_node
    )
    return node 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:22,代码来源:custom_hypothesis_support.py

示例6: _transfer

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def _transfer(self, block: CFGBlock, in_facts: Set[str], local_vars: Set[str]) -> Set[str]:
        gen = in_facts.copy()
        kill = set()
        for statement in block.statements:
            if isinstance(statement, astroid.FunctionDef):
                continue
            for node in statement.nodes_of_class((astroid.AssignName, astroid.DelName, astroid.Name),
                                              astroid.FunctionDef):
                if isinstance(node, astroid.AssignName):
                    gen.add(node.name)
                elif isinstance(node, astroid.DelName):
                    kill.add(node.name)
                else:
                    name = node.name
                    # comment out 'self.config....' check when running tests
                    if not (name in astroid.Module.scope_attrs or utils.is_builtin(name)) \
                            and name in local_vars \
                            and name not in gen.difference(kill):
                        self._possibly_undefined.add(node)
                    elif node in self._possibly_undefined:
                        self._possibly_undefined.remove(node)
        return gen.difference(kill) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:24,代码来源:possibly_undefined_checker.py

示例7: _get_assigns

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def _get_assigns(self, node: Union[astroid.FunctionDef, astroid.Module]) -> Set[str]:
        """Returns a set of all local and parameter variables that could be
        defined in the program (either a function or module).

        IF a variable 'v' is defined in a function and there is no global/nonlocal
        statement applied to 'v' THEN 'v' is a local variable.

        Note that `local variable` in the context of a module level analysis,
        refers to global variables.
        """
        assigns = set()
        kills = set()
        for name, nodes in node.scope().locals.items():
            if any(isinstance(elem, astroid.AssignName) for elem in nodes):
                assigns.add(name)
        for statement in node.nodes_of_class((astroid.Nonlocal, astroid.Global,
                                              astroid.ImportFrom, astroid.Import), astroid.FunctionDef):
            for name in statement.names:
                if type(name) is tuple:
                    # name[1] is the alias of the imported object/var name[0]
                    # name[1] == str or None
                    name = name[1] or name[0]
                kills.add(name)

        return assigns.difference(kills) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:27,代码来源:possibly_undefined_checker.py

示例8: _get_assigns

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def _get_assigns(self, node: Union[astroid.FunctionDef, astroid.Module]) -> Set[str]:
        """Returns a set of all local and parameter variables that could be
        defined in the program (either a function or module).

        IF a variable 'v' is defined in a function and there is no global/nonlocal
        statement applied to 'v' THEN 'v' is a local variable.

        Note that `local variable` in the context of a module level analysis,
        refers to global variables.
        """
        assigns = set()
        kills = set()
        for name, nodes in node.locals.items():
            if any(isinstance(elem, astroid.AssignName) for elem in nodes):
                assigns.add(name)
        return assigns.difference(kills) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:18,代码来源:redundant_assignment_checker.py

示例9: display

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def display(cfgs: Dict[NodeNG, ControlFlowGraph],
            filename: str, view: bool = True) -> None:
    graph = graphviz.Digraph(name=filename, **GRAPH_OPTIONS)
    for node, cfg in cfgs.items():
        if isinstance(node, astroid.Module):
            subgraph_label = '__main__'
        elif isinstance(node, astroid.FunctionDef):
            subgraph_label = node.name
        else:
            continue
        with graph.subgraph(name=f'cluster_{id(node)}') as c:
            visited = set()
            _visit(cfg.start, c, visited)
            for block in cfg.unreachable_blocks:
                _visit(block, c, visited)
            c.attr(label=subgraph_label)

    graph.render(filename, view=view) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:20,代码来源:draw_cfg.py

示例10: visit_importfrom

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_importfrom(self, node):
        if node.modname == "__future__":
            for name, _ in node.names:
                if name == "division":
                    self._future_division = True
                elif name == "absolute_import":
                    self._future_absolute_import = True
        else:
            if not self._future_absolute_import:
                if self.linter.is_message_enabled("no-absolute-import"):
                    self.add_message("no-absolute-import", node=node)
                    self._future_absolute_import = True
            if not _is_conditional_import(node) and not node.level:
                self._warn_if_deprecated(node, node.modname, {x[0] for x in node.names})

        if node.names[0][0] == "*":
            if self.linter.is_message_enabled("import-star-module-level"):
                if not isinstance(node.scope(), astroid.Module):
                    self.add_message("import-star-module-level", node=node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:21,代码来源:python3.py

示例11: visit_attribute

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_attribute(self, node):
        """Look for removed attributes"""
        if node.attrname == "xreadlines":
            self.add_message("xreadlines-attribute", node=node)
            return

        exception_message = "message"
        try:
            for inferred in node.expr.infer():
                if isinstance(inferred, astroid.Instance) and utils.inherit_from_std_ex(
                    inferred
                ):
                    if node.attrname == exception_message:

                        # Exceptions with .message clearly defined are an exception
                        if exception_message in inferred.instance_attrs:
                            continue
                        self.add_message("exception-message-attribute", node=node)
                if isinstance(inferred, astroid.Module):
                    self._warn_if_deprecated(
                        node, inferred.name, {node.attrname}, report_on_modules=False
                    )
        except astroid.InferenceError:
            return 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:26,代码来源:python3.py

示例12: _get_import_name

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def _get_import_name(importnode, modname):
    """Get a prepared module name from the given import node

    In the case of relative imports, this will return the
    absolute qualified module name, which might be useful
    for debugging. Otherwise, the initial module name
    is returned unchanged.
    """
    if isinstance(importnode, astroid.ImportFrom):
        if importnode.level:
            root = importnode.root()
            if isinstance(root, astroid.Module):
                modname = root.relative_to_absolute_name(
                    modname, level=importnode.level
                )
    return modname 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:18,代码来源:imports.py

示例13: visit_import

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_import(self, node):
        """triggered when an import statement is seen"""
        self._check_reimport(node)
        self._check_import_as_rename(node)

        modnode = node.root()
        names = [name for name, _ in node.names]
        if len(names) >= 2:
            self.add_message("multiple-imports", args=", ".join(names), node=node)

        for name in names:
            self._check_deprecated_module(node, name)
            imported_module = self._get_imported_module(node, name)
            if isinstance(node.parent, astroid.Module):
                # Allow imports nested
                self._check_position(node)
            if isinstance(node.scope(), astroid.Module):
                self._record_import(node, imported_module)

            if imported_module is None:
                continue

            self._check_relative_import(modnode, node, imported_module, name)
            self._add_imported_module(node, imported_module.name) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:26,代码来源:imports.py

示例14: visit_functiondef

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def visit_functiondef(self, node):
        if not self.linter.is_message_enabled("wrong-import-position", node.fromlineno):
            return
        # If it is the first non import instruction of the module, record it.
        if self._first_non_import_node:
            return

        # Check if the node belongs to an `If` or a `Try` block. If they
        # contain imports, skip recording this node.
        if not isinstance(node.parent.scope(), astroid.Module):
            return

        root = node
        while not isinstance(root.parent, astroid.Module):
            root = root.parent

        if isinstance(root, (astroid.If, astroid.TryFinally, astroid.TryExcept)):
            if any(root.nodes_of_class((astroid.Import, astroid.ImportFrom))):
                return

        self._first_non_import_node = node 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:23,代码来源:imports.py

示例15: _get_nomember_msgid_hint

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Module [as 别名]
def _get_nomember_msgid_hint(self, node, owner):
        suggestions_are_possible = self._suggestion_mode and isinstance(
            owner, astroid.Module
        )
        if suggestions_are_possible and _is_c_extension(owner):
            msg = "c-extension-no-member"
            hint = ""
        else:
            msg = "no-member"
            if self.config.missing_member_hint:
                hint = _missing_member_hint(
                    owner,
                    node.attrname,
                    self.config.missing_member_hint_distance,
                    self.config.missing_member_max_choices,
                )
            else:
                hint = ""
        return msg, hint 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:21,代码来源:typecheck.py


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