當前位置: 首頁>>代碼示例>>Python>>正文


Python interfaces.ITokenChecker方法代碼示例

本文整理匯總了Python中pylint.interfaces.ITokenChecker方法的典型用法代碼示例。如果您正苦於以下問題:Python interfaces.ITokenChecker方法的具體用法?Python interfaces.ITokenChecker怎麽用?Python interfaces.ITokenChecker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pylint.interfaces的用法示例。


在下文中一共展示了interfaces.ITokenChecker方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: build_message_def

# 需要導入模塊: from pylint import interfaces [as 別名]
# 或者: from pylint.interfaces import ITokenChecker [as 別名]
def build_message_def(checker, msgid, msg_tuple):
    if implements(checker, (IRawChecker, ITokenChecker)):
        default_scope = WarningScope.LINE
    else:
        default_scope = WarningScope.NODE
    options = {}
    if len(msg_tuple) > 3:
        (msg, symbol, descr, options) = msg_tuple
    elif len(msg_tuple) > 2:
        (msg, symbol, descr) = msg_tuple
    else:
        # messages should have a symbol, but for backward compatibility
        # they may not.
        (msg, descr) = msg_tuple
        warnings.warn("[pylint 0.26] description of message %s doesn't include "
                      "a symbolic name" % msgid, DeprecationWarning)
        symbol = None
    options.setdefault('scope', default_scope)
    return MessageDefinition(checker, msgid, msg, descr, symbol, **options) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:21,代碼來源:utils.py

示例2: build_message_def

# 需要導入模塊: from pylint import interfaces [as 別名]
# 或者: from pylint.interfaces import ITokenChecker [as 別名]
def build_message_def(checker, msgid, msg_tuple):
    if implements(checker, (IRawChecker, ITokenChecker)):
        default_scope = WarningScope.LINE
    else:
        default_scope = WarningScope.NODE
    options = {}
    if len(msg_tuple) > 3:
        (msg, symbol, descr, options) = msg_tuple
    elif len(msg_tuple) > 2:
        (msg, symbol, descr) = msg_tuple
    else:
        # messages should have a symbol, but for backward compatibility
        # they may not.
        (msg, descr) = msg_tuple
        warnings.warn(
            "[pylint 0.26] description of message %s doesn't include "
            "a symbolic name" % msgid,
            DeprecationWarning,
        )
        symbol = None
    options.setdefault("scope", default_scope)
    return MessageDefinition(checker, msgid, msg, descr, symbol, **options) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:24,代碼來源:utils.py

示例3: _do_check

# 需要導入模塊: from pylint import interfaces [as 別名]
# 或者: from pylint.interfaces import ITokenChecker [as 別名]
def _do_check(self, files_or_modules):
        walker = utils.PyLintASTWalker(self)
        _checkers = self.prepare_checkers()
        tokencheckers = [c for c in _checkers
                         if interfaces.implements(c, interfaces.ITokenChecker)
                         and c is not self]
        rawcheckers = [c for c in _checkers
                       if interfaces.implements(c, interfaces.IRawChecker)]
        # notify global begin
        for checker in _checkers:
            checker.open()
            if interfaces.implements(checker, interfaces.IAstroidChecker):
                walker.add_checker(checker)
        # build ast and check modules or packages
        for descr in self.expand_files(files_or_modules):
            modname, filepath, is_arg = descr['name'], descr['path'], descr['isarg']
            if not self.should_analyze_file(modname, filepath, is_argument=is_arg):
                continue

            self.set_current_module(modname, filepath)
            # get the module representation
            ast_node = self.get_ast(filepath, modname)
            if ast_node is None:
                continue
            # XXX to be correct we need to keep module_msgs_state for every
            # analyzed module (the problem stands with localized messages which
            # are only detected in the .close step)
            self.file_state = utils.FileState(descr['basename'])
            self._ignore_file = False
            # fix the current file (if the source file was not available or
            # if it's actually a c extension)
            self.current_file = ast_node.file # pylint: disable=maybe-no-member
            self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
            # warn about spurious inline messages handling
            spurious_messages = self.file_state.iter_spurious_suppression_messages(self.msgs_store)
            for msgid, line, args in spurious_messages:
                self.add_message(msgid, line, None, args)
        # notify global end
        self.stats['statement'] = walker.nbstatements
        for checker in reversed(_checkers):
            checker.close() 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:43,代碼來源:lint.py

示例4: check_astroid_module

# 需要導入模塊: from pylint import interfaces [as 別名]
# 或者: from pylint.interfaces import ITokenChecker [as 別名]
def check_astroid_module(self, ast_node, walker,
                             rawcheckers, tokencheckers):
        """Check a module from its astroid representation."""
        try:
            tokens = utils.tokenize_module(ast_node)
        except tokenize.TokenError as ex:
            self.add_message('syntax-error', line=ex.args[1][0], args=ex.args[0])
            return None

        if not ast_node.pure_python:
            self.add_message('raw-checker-failed', args=ast_node.name)
        else:
            #assert astroid.file.endswith('.py')
            # invoke ITokenChecker interface on self to fetch module/block
            # level options
            self.process_tokens(tokens)
            if self._ignore_file:
                return False
            # walk ast to collect line numbers
            self.file_state.collect_block_lines(self.msgs_store, ast_node)
            # run raw and tokens checkers
            for checker in rawcheckers:
                checker.process_module(ast_node)
            for checker in tokencheckers:
                checker.process_tokens(tokens)
        # generate events to astroid checkers
        walker.walk(ast_node)
        return True

    # IAstroidChecker interface ################################################# 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:32,代碼來源:lint.py

示例5: check_astroid_module

# 需要導入模塊: from pylint import interfaces [as 別名]
# 或者: from pylint.interfaces import ITokenChecker [as 別名]
def check_astroid_module(self, ast_node, walker, rawcheckers, tokencheckers):
        """Check a module from its astroid representation."""
        try:
            tokens = utils.tokenize_module(ast_node)
        except tokenize.TokenError as ex:
            self.add_message("syntax-error", line=ex.args[1][0], args=ex.args[0])
            return None

        if not ast_node.pure_python:
            self.add_message("raw-checker-failed", args=ast_node.name)
        else:
            # assert astroid.file.endswith('.py')
            # invoke ITokenChecker interface on self to fetch module/block
            # level options
            self.process_tokens(tokens)
            if self._ignore_file:
                return False
            # walk ast to collect line numbers
            self.file_state.collect_block_lines(self.msgs_store, ast_node)
            # run raw and tokens checkers
            for checker in rawcheckers:
                checker.process_module(ast_node)
            for checker in tokencheckers:
                checker.process_tokens(tokens)
        # generate events to astroid checkers
        walker.walk(ast_node)
        return True

    # IAstroidChecker interface ################################################# 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:31,代碼來源:lint.py

示例6: _do_check

# 需要導入模塊: from pylint import interfaces [as 別名]
# 或者: from pylint.interfaces import ITokenChecker [as 別名]
def _do_check(self, files_or_modules):
        walker = utils.PyLintASTWalker(self)
        _checkers = self.prepare_checkers()
        tokencheckers = [
            c
            for c in _checkers
            if interfaces.implements(c, interfaces.ITokenChecker) and c is not self
        ]
        rawcheckers = [
            c for c in _checkers if interfaces.implements(c, interfaces.IRawChecker)
        ]
        # notify global begin
        for checker in _checkers:
            checker.open()
            if interfaces.implements(checker, interfaces.IAstroidChecker):
                walker.add_checker(checker)
        # build ast and check modules or packages
        for descr in self.expand_files(files_or_modules):
            modname, filepath, is_arg = descr["name"], descr["path"], descr["isarg"]
            if not self.should_analyze_file(modname, filepath, is_argument=is_arg):
                continue

            self.set_current_module(modname, filepath)
            # get the module representation
            ast_node = self.get_ast(filepath, modname)
            if ast_node is None:
                continue
            # XXX to be correct we need to keep module_msgs_state for every
            # analyzed module (the problem stands with localized messages which
            # are only detected in the .close step)
            self.file_state = utils.FileState(descr["basename"])
            self._ignore_file = False
            # fix the current file (if the source file was not available or
            # if it's actually a c extension)
            self.current_file = ast_node.file  # pylint: disable=maybe-no-member
            self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
            # warn about spurious inline messages handling
            spurious_messages = self.file_state.iter_spurious_suppression_messages(
                self.msgs_store
            )
            for msgid, line, args in spurious_messages:
                self.add_message(msgid, line, None, args)
        # notify global end
        self.stats["statement"] = walker.nbstatements
        for checker in reversed(_checkers):
            checker.close() 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:48,代碼來源:lint.py


注:本文中的pylint.interfaces.ITokenChecker方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。