當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。