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


Python astroid.Name方法代码示例

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


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

示例1: get_setters_property_name

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def get_setters_property_name(node):
    """Get the name of the property that the given node is a setter for.

    :param node: The node to get the property name for.
    :type node: str

    :rtype: str or None
    :returns: The name of the property that the node is a setter for,
        or None if one could not be found.
    """
    decorators = node.decorators.nodes if node.decorators else []
    for decorator in decorators:
        if (isinstance(decorator, astroid.Attribute) and
                decorator.attrname == "setter" and
                isinstance(decorator.expr, astroid.Name)):
            return decorator.expr.name
    return None 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:19,代码来源:_check_docs_utils.py

示例2: _check_name_used_prior_global

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def _check_name_used_prior_global(self, node):

        scope_globals = {
            name: child
            for child in node.nodes_of_class(astroid.Global)
            for name in child.names
            if child.scope() is node
        }

        for node_name in node.nodes_of_class(astroid.Name):
            if node_name.scope() is not node:
                continue

            name = node_name.name
            corresponding_global = scope_globals.get(name)
            if not corresponding_global:
                continue

            global_lineno = corresponding_global.fromlineno
            if global_lineno and global_lineno > node_name.fromlineno:
                self.add_message('used-prior-global-declaration',
                                 node=node_name, args=(name, )) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:24,代码来源:base.py

示例3: visit_call

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def visit_call(self, node):
        """visit a Call node -> check if this is not a blacklisted builtin
        call and check for * or ** use
        """
        if isinstance(node.func, astroid.Name):
            name = node.func.name
            # ignore the name if it's not a builtin (i.e. not defined in the
            # locals nor globals scope)
            if not (name in node.frame() or
                    name in node.root()):
                if name == 'exec':
                    self.add_message('exec-used', node=node)
                elif name == 'reversed':
                    self._check_reversed(node)
                elif name == 'eval':
                    self.add_message('eval-used', node=node) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:18,代码来源:base.py

示例4: visit_call

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def visit_call(self, node: NodeNG) -> None:
        """Called for every function call in the source code."""
        if not isinstance(node.func, astroid.Name):
            # It isn't a simple name, can't deduce what function it is.
            return

        if node.func.name not in self.TRANSLATION_FUNCTIONS:
            # Not a function we care about.
            return

        if not self.linter.is_message_enabled(self.MESSAGE_ID, line=node.fromlineno):
            return

        first = node.args[0]
        if isinstance(first, astroid.Const):
            if isinstance(first.value, six.string_types):
                # The first argument is a constant string! All is well!
                return

        # Bad!
        self.add_message(self.MESSAGE_ID, args=node.func.name, node=node) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:23,代码来源:l18n_check.py

示例5: test_order

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_order():
    src = """
    a, *b, c = [1, 2, 3, 4]
    a
    b
    c
    """
    ast_mod, ti = cs._parse_text(src, reset=True)
    for name_node in ast_mod.nodes_of_class(astroid.Name):
        assert not isinstance(name_node.inf_type, TypeFail)
        if name_node.name == 'a':
            assert name_node.inf_type.getValue() == int
        elif name_node.name == 'b':
            assert name_node.inf_type.getValue() == List[int]
        elif name_node.name == 'c':
            assert name_node.inf_type.getValue() == int 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:18,代码来源:test_starred.py

示例6: test_mixed_tuple_three_var

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_mixed_tuple_three_var():
    src = """
    a, *b, c = (1, "Hello", False, "Goodbye", 4, "What")
    a
    b
    c
    """
    ast_mod, ti = cs._parse_text(src, reset=True)
    for name_node in ast_mod.nodes_of_class(astroid.Name):
        assert not isinstance(name_node.inf_type, TypeFail)
        if name_node.name == 'a':
            assert name_node.inf_type.getValue() == int
        elif name_node.name == 'b':
            assert name_node.inf_type.getValue() == List[Any]
        elif name_node.name == 'c':
            assert name_node.inf_type.getValue() == str 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:18,代码来源:test_starred.py

示例7: test_mixed_tuple_four_var

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_mixed_tuple_four_var():
    src = """
    a, *b, c, d = (1, "Hello", "Good morning", "Goodbye", 4, "What")
    a
    b
    c
    d
    """
    ast_mod, ti = cs._parse_text(src, reset=True)
    for name_node in ast_mod.nodes_of_class(astroid.Name):
        assert not isinstance(name_node.inf_type, TypeFail)
        if name_node.name == 'a':
            assert name_node.inf_type.getValue() == int
        elif name_node.name == 'b':
            assert name_node.inf_type.getValue() == List[str]
        elif name_node.name == 'c':
            assert name_node.inf_type.getValue() == int
        elif name_node.name == 'd':
            assert name_node.inf_type.getValue() == str 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:21,代码来源:test_starred.py

示例8: test_no_messages_simple

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_simple(self):
        src = """
        def test(x):
            x = 10
            if True:
                return x
            return x
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        name_node_a, name_node_b = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_module(mod)
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_a)
            self.checker.visit_name(name_node_b) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:20,代码来源:test_possibly_undefined_checker.py

示例9: test_no_messages_with_import

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_with_import(self):
        src = """
        import j

        y = 0
        if y > 10:
            j = 10
        else:
            y = 5
        print(j)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        name_node_y, name_node_print, name_node_j = mod.nodes_of_class(
            astroid.Name)
        with self.assertNoMessages():
            self.checker.visit_module(mod)
            self.checker.visit_name(name_node_y)
            self.checker.visit_name(name_node_print)
            self.checker.visit_name(name_node_j) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:22,代码来源:test_possibly_undefined_checker.py

示例10: test_no_messages_with_import_from

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_with_import_from(self):
        src = """
        from random import j
        
        y = 0
        if y > 10:
            j = 10
        else:
            y = 5
        print(j)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        name_node_y, name_node_print, name_node_j = mod.nodes_of_class(astroid.Name)
        with self.assertNoMessages():
            self.checker.visit_module(mod)
            self.checker.visit_name(name_node_y)
            self.checker.visit_name(name_node_print)
            self.checker.visit_name(name_node_j) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:21,代码来源:test_possibly_undefined_checker.py

示例11: test_no_messages_if_else

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_if_else(self):
        src = """
        def test(x):
            if True:
                y = 10
            else:
                y = 20
            print(y)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        _, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_possibly_undefined_checker.py

示例12: test_no_messages_if_else_with_ann_assign

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_if_else_with_ann_assign(self):
        src = """
        def test(x):
            if True:
                y: int = 10
            else:
                y = 20
            print(y)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        _, _, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_possibly_undefined_checker.py

示例13: test_no_messages_complex

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_complex(self):
        src = """
        def test(x):
            if True:
                y = 10
            else:
                for j in range(10):
                    if j > 10:
                        y = 10
                        break
                else:
                    y = 10
            return y
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        _, _, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:24,代码来源:test_possibly_undefined_checker.py

示例14: test_no_messages_with_nonlocal

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_with_nonlocal(self):
        src = """
        def test(x):
            x = 10
            nonlocal y
            if True:
                y = 10
            print(y)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        __, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_possibly_undefined_checker.py

示例15: test_no_messages_with_global

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Name [as 别名]
def test_no_messages_with_global(self):
        src = """
        def test(x):
            x = 10
            if True:
                global y
            else:
                y = 10
            print(y)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        _, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:20,代码来源:test_possibly_undefined_checker.py


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