How to use the pyflakes.checker function in pyflakes

To help you get started, we’ve selected a few pyflakes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / nova / tools / flakes.py View on Github external
def main():
    checker.Checker.builtIns = (set(dir(builtins)) |
                                set(['_']) |
                                set(checker._MAGIC_GLOBALS))
    sys.exit(pyflakes.api.main())
github openstack / keystone / tools / flakes.py View on Github external
def main():
    checker.Checker.builtIns = (set(dir(builtins)) |
                                set(['_']) |
                                set(checker._MAGIC_GLOBALS))
    sys.exit(pyflakes.api.main())
github spyder-ide / spyder / external-py3 / pyflakes / api.py View on Github external
(lineno, offset, text) = value.lineno, value.offset, value.text

        # If there's an encoding problem with the file, the text is None.
        if text is None:
            # Avoid using msg, since for the only known case, it contains a
            # bogus message that claims the encoding the file declared was
            # unknown.
            reporter.unexpectedError(filename, 'problem decoding source')
        else:
            reporter.syntaxError(filename, msg, lineno, offset, text)
        return 1
    except Exception:
        reporter.unexpectedError(filename, 'problem decoding source')
        return 1
    # Okay, it's syntactically valid.  Now check it.
    w = checker.Checker(tree, filename)
    w.messages.sort(key=lambda m: m.lineno)
    for warning in w.messages:
        reporter.flake(warning)
    return len(w.messages)
github marslo / myvim / Configurations / bundle / pyflakes / pyflakes / api.py View on Github external
    @return: The number of warnings emitted.
    @rtype: C{int}
    """
    if reporter is None:
        reporter = modReporter._makeDefaultReporter()
    # First, compile into an AST and handle syntax errors.
    try:
        tree = ast.parse(codeString, filename=filename)
    except SyntaxError:
        value = sys.exc_info()[1]
        msg = value.args[0]

        (lineno, offset, text) = value.lineno, value.offset, value.text

        if checker.PYPY:
            if text is None:
                lines = codeString.splitlines()
                if len(lines) >= lineno:
                    text = lines[lineno - 1]
                    if sys.version_info >= (3, ) and isinstance(text, bytes):
                        try:
                            text = text.decode('ascii')
                        except UnicodeDecodeError:
                            text = None
            offset -= 1

        # If there's an encoding problem with the file, the text is None.
        if text is None:
            # Avoid using msg, since for the only known case, it contains a
            # bogus message that claims the encoding the file declared was
            # unknown.
github DamnWidget / anaconda / anaconda_lib / linting / linter.py View on Github external
"""Check the code with pyflakes to find errors
        """

        class FakeLoc:
            lineno = 0

        try:
            code = code.encode('utf8') + b'\n'
            tree = compile(code, filename or '', 'exec', _ast.PyCF_ONLY_AST)
        except (SyntaxError, IndentationError):
            return self._handle_syntactic_error(code, filename)
        except ValueError as error:
            return [PythonError(filename, FakeLoc(), error.args[0])]
        else:
            # the file is syntactically valid, check it now
            w = pyflakes.Checker(tree, filename, ignore)

            return w.messages
github pkgcore / snakeoil / snakeoil / pyflakes_extension.py View on Github external
#!/usr/bin/env python
# Copyright: 2011 Brian Harring 
# License: GPL2/BSD 3 clause

import ast as _ast
from pyflakes import checker as _checker, messages as _messages

_Checker = _checker.Checker

SNAKEOIL_LOC = 'snakeoil.demandload.demandload'
SNAKEOIL_REGEX_LOC = 'snakeoil.demandload.demand_compile_regexp'
SNAKEOIL_MOD = 'snakeoil.demandload'
from snakeoil.demandload import parse_imports as parse_demandload


class BadDemandloadCall(_messages.Message):

    message = 'bad invocation of demandload; should be demandload(globals(), *targets)'

    def __init__(self, filename, lineno, target=None):
        _messages.Message.__init__(self, filename, lineno)
        if target is not None:
            self.message = self.message + ': exception %r will occur'
            self.message_args = (target,)
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / pymode / libs / pyflakes / api.py View on Github external
    @return: The number of warnings emitted.
    @rtype: C{int}
    """
    if reporter is None:
        reporter = modReporter._makeDefaultReporter()
    # First, compile into an AST and handle syntax errors.
    try:
        tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
    except SyntaxError:
        value = sys.exc_info()[1]
        msg = value.args[0]

        (lineno, offset, text) = value.lineno, value.offset, value.text

        if checker.PYPY:
            if text is None:
                lines = codeString.splitlines()
                if len(lines) >= lineno:
                    text = lines[lineno - 1]
                    if sys.version_info >= (3, ) and isinstance(text, bytes):
                        try:
                            text = text.decode('ascii')
                        except UnicodeDecodeError:
                            text = None
            offset -= 1

        # If there's an encoding problem with the file, the text is None.
        if text is None:
            # Avoid using msg, since for the only known case, it contains a
            # bogus message that claims the encoding the file declared was
            # unknown.
github reingart / rad2py / ide2py / checker.py View on Github external
def __init__(self, filename):
        code_string = open(filename).read()
        tree = compile(code_string, filename, "exec", _ast.PyCF_ONLY_AST)
        self.checker = pyflakes.checker.Checker(tree, filename)
        self.checker.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
github DamnWidget / anaconda / anaconda_lib / linting / anaconda_pyflakes.py View on Github external
class FakeLoc:
            lineno = 0

        try:
            fname = ''
            if filename is not None:
                fname = filename.encode('utf8') or ''
            code = code.encode('utf8') + b'\n'
            tree = compile(code, fname, 'exec', _ast.PyCF_ONLY_AST)
        except (SyntaxError, IndentationError):
            return self._handle_syntactic_error(code, filename)
        except ValueError as error:
            return [PyFlakesError(filename, FakeLoc(), 'E', error.args[0]), []]
        else:
            # the file is syntactically valid, check it now
            w = pyflakes.Checker(tree, filename, ignore)

            return w.messages
github marslo / myvim / Configurations / Offline_Packages / bundle / pyflakes / pyflakes / api.py View on Github external
offset -= 1

        # If there's an encoding problem with the file, the text is None.
        if text is None:
            # Avoid using msg, since for the only known case, it contains a
            # bogus message that claims the encoding the file declared was
            # unknown.
            reporter.unexpectedError(filename, 'problem decoding source')
        else:
            reporter.syntaxError(filename, msg, lineno, offset, text)
        return 1
    except Exception:
        reporter.unexpectedError(filename, 'problem decoding source')
        return 1
    # Okay, it's syntactically valid.  Now check it.
    w = checker.Checker(tree, filename)
    w.messages.sort(key=lambda m: m.lineno)
    for warning in w.messages:
        reporter.flake(warning)
    return len(w.messages)