Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
if checker.messages.UndefinedName.message != "E0602 undefined name %r":
monkey_patch_messages(checker.messages)
checker.messages.UnusedImport.message = "W0611 %r imported but unused"
checker.messages.RedefinedWhileUnused.message = "W0404 redefinition of unused %r from line %r"
checker.messages.RedefinedInListComp.message = "W0621 list comprehension redefines %r from line %r"
checker.messages.ImportShadowedByLoopVar.message = "W0621 import %r from line %r shadowed by loop variable"
checker.messages.ImportStarUsed.message = "W0401 'from %s import *' used; unable to detect undefined names"
checker.messages.ImportStarUsage.message = "W0401 '%s may be undefined, or defined from star imports: %s'"
checker.messages.UndefinedName.message = "E0602 undefined name %r"
checker.messages.DoctestSyntaxError.message = "W0511 syntax error in doctest"
checker.messages.UndefinedExport.message = "E0603 undefined name %r in __all__"
checker.messages.UndefinedLocal.message = "E0602 local variable %r (defined in enclosing scope on line %r) referenced before assignment"
checker.messages.DuplicateArgument.message = "E1122 duplicate argument %r in function definition"
checker.messages.LateFutureImport.message = "W0410 future import(s) %r after other statements"
checker.messages.UnusedVariable.message = "W0612 local variable %r is assigned to but never used"
checker.messages.ReturnWithArgsInsideGenerator.message = "E0106 'return' with argument inside generator"
checker.messages.ReturnOutsideFunction.message = "E0104 'return' outside function"
class Linter(Abstract):
"""Pyflakes runner."""
@staticmethod
def run(path, code=None, params=None, **meta):
"""Check code with pyflakes.
:return list: List of errors.
"""
import _ast
builtins = params.get("builtins", "")
checker.messages.UnusedImport.message = "W0611 %r imported but unused"
checker.messages.RedefinedWhileUnused.message = "W0404 redefinition of unused %r from line %r"
checker.messages.RedefinedInListComp.message = "W0621 list comprehension redefines %r from line %r"
checker.messages.ImportShadowedByLoopVar.message = "W0621 import %r from line %r shadowed by loop variable"
checker.messages.ImportStarUsed.message = "W0401 'from %s import *' used; unable to detect undefined names"
checker.messages.ImportStarUsage.message = "W0401 '%s may be undefined, or defined from star imports: %s'"
checker.messages.UndefinedName.message = "E0602 undefined name %r"
checker.messages.DoctestSyntaxError.message = "W0511 syntax error in doctest"
checker.messages.UndefinedExport.message = "E0603 undefined name %r in __all__"
checker.messages.UndefinedLocal.message = "E0602 local variable %r (defined in enclosing scope on line %r) referenced before assignment"
checker.messages.DuplicateArgument.message = "E1122 duplicate argument %r in function definition"
checker.messages.LateFutureImport.message = "W0410 future import(s) %r after other statements"
checker.messages.UnusedVariable.message = "W0612 local variable %r is assigned to but never used"
checker.messages.ReturnWithArgsInsideGenerator.message = "E0106 'return' with argument inside generator"
checker.messages.ReturnOutsideFunction.message = "E0104 'return' outside function"
class Linter(Abstract):
"""Pyflakes runner."""
@staticmethod
def run(path, code=None, params=None, **meta):
"""Check code with pyflakes.
:return list: List of errors.
"""
import _ast
builtins = params.get("builtins", "")
"""Pyflakes support."""
from pyflakes import checker
from pylama.lint import Linter as Abstract
checker.messages.UnusedImport.message = "W0611 %r imported but unused"
checker.messages.RedefinedWhileUnused.message = "W0404 redefinition of unused %r from line %r"
checker.messages.RedefinedInListComp.message = "W0621 list comprehension redefines %r from line %r"
checker.messages.ImportShadowedByLoopVar.message = "W0621 import %r from line %r shadowed by loop variable"
checker.messages.ImportStarUsed.message = "W0401 'from %s import *' used; unable to detect undefined names"
checker.messages.ImportStarUsage.message = "W0401 '%s may be undefined, or defined from star imports: %s'"
checker.messages.UndefinedName.message = "E0602 undefined name %r"
checker.messages.DoctestSyntaxError.message = "W0511 syntax error in doctest"
checker.messages.UndefinedExport.message = "E0603 undefined name %r in __all__"
checker.messages.UndefinedLocal.message = "E0602 local variable %r (defined in enclosing scope on line %r) referenced before assignment"
checker.messages.DuplicateArgument.message = "E1122 duplicate argument %r in function definition"
checker.messages.LateFutureImport.message = "W0410 future import(s) %r after other statements"
checker.messages.UnusedVariable.message = "W0612 local variable %r is assigned to but never used"
checker.messages.ReturnWithArgsInsideGenerator.message = "E0106 'return' with argument inside generator"
checker.messages.ReturnOutsideFunction.message = "E0104 'return' outside function"
class Linter(Abstract):
"""Pyflakes runner."""
@staticmethod
def run(path, code=None, params=None, **meta):
"""Check code with pyflakes.
from pyflakes import checker
from pylava.lint import Linter as Abstract
checker.messages.UnusedImport.message = "W0611 %r imported but unused"
checker.messages.RedefinedWhileUnused.message = "W0404 redefinition of unused %r from line %r"
checker.messages.RedefinedInListComp.message = "W0621 list comprehension redefines %r from line %r"
checker.messages.ImportShadowedByLoopVar.message = "W0621 import %r from line %r shadowed by loop variable"
checker.messages.ImportStarUsed.message = "W0401 'from %s import *' used; unable to detect undefined names"
checker.messages.ImportStarUsage.message = "W0401 '%s may be undefined, or defined from star imports: %s'"
checker.messages.UndefinedName.message = "E0602 undefined name %r"
checker.messages.DoctestSyntaxError.message = "W0511 syntax error in doctest"
checker.messages.UndefinedExport.message = "E0603 undefined name %r in __all__"
checker.messages.UndefinedLocal.message = "E0602 local variable %r (defined in enclosing scope on line %r) referenced before assignment"
checker.messages.DuplicateArgument.message = "E1122 duplicate argument %r in function definition"
checker.messages.LateFutureImport.message = "W0410 future import(s) %r after other statements"
checker.messages.UnusedVariable.message = "W0612 local variable %r is assigned to but never used"
checker.messages.ReturnWithArgsInsideGenerator.message = "E0106 'return' with argument inside generator"
checker.messages.ReturnOutsideFunction.message = "E0104 'return' outside function"
class Linter(Abstract):
"""Pyflakes runner."""
@staticmethod
def run(path, code=None, params=None, **meta):
"""Check code with pyflakes.
:return list: List of errors.
"""
pyflakes.messages.RedefinedWhileUnused,
pyflakes.messages.UndefinedName,
pyflakes.messages.UndefinedExport,
pyflakes.messages.UndefinedLocal,
pyflakes.messages.UnusedVariable)) and
error.__class__.__name__ not in explicit_ignore):
error_data['len'] = len(error.message_args[0])
error_data['regex'] = (
r'((and|or|not|if|elif|while|in)\s+|[+\-*^%%<>=\(\{{])*\s'
'*(?P[\w\.]*{0}[\w]*)'.format(re.escape(
error.message_args[0]
))
)
error_list.append(error_data)
elif isinstance(error, pyflakes.messages.ImportShadowedByLoopVar):
regex = 'for\s+(?P[\w]*{0}[\w*])'.format(
re.escape(error.message_args[0])
)
error_data['regex'] = regex
error_list.append(error_data)
elif (isinstance(
error, (
pyflakes.messages.UnusedImport,
pyflakes.messages.ImportStarUsed)) and
error.__class__.__name__ not in explicit_ignore):
if isinstance(error, pyflakes.messages.ImportStarUsed):
word = '*'
else:
word = error.message_args[0]
linematch = '(from\s+[\w_\.]+\s+)?import\s+(?P[^#;]+)'
def __ge__(self, other):
return mycmp(self.obj, other.obj) >= 0
def __ne__(self, other):
return mycmp(self.obj, other.obj) != 0
def __hash__(self):
raise TypeError('hash not implemented')
return K
else:
from functools import cmp_to_key
pyflakes.messages.Message.__str__ = (
lambda self: self.message % self.message_args
)
class LintError(pyflakes.messages.Message):
"""Lint error base class
"""
def __init__(self, filename, loc, level, message, message_args, **kwargs):
super(LintError, self).__init__(filename, loc)
self.level = level
self.message = message
self.message_args = message_args
offset = kwargs.get('offset')
text = kwargs.get('text')
"""Pyflakes support."""
from pyflakes import checker
from pylava.lint import Linter as Abstract
checker.messages.UnusedImport.message = "W0611 %r imported but unused"
checker.messages.RedefinedWhileUnused.message = "W0404 redefinition of unused %r from line %r"
checker.messages.RedefinedInListComp.message = "W0621 list comprehension redefines %r from line %r"
checker.messages.ImportShadowedByLoopVar.message = "W0621 import %r from line %r shadowed by loop variable"
checker.messages.ImportStarUsed.message = "W0401 'from %s import *' used; unable to detect undefined names"
checker.messages.ImportStarUsage.message = "W0401 '%s may be undefined, or defined from star imports: %s'"
checker.messages.UndefinedName.message = "E0602 undefined name %r"
checker.messages.DoctestSyntaxError.message = "W0511 syntax error in doctest"
checker.messages.UndefinedExport.message = "E0603 undefined name %r in __all__"
checker.messages.UndefinedLocal.message = "E0602 local variable %r (defined in enclosing scope on line %r) referenced before assignment"
checker.messages.DuplicateArgument.message = "E1122 duplicate argument %r in function definition"
checker.messages.LateFutureImport.message = "W0410 future import(s) %r after other statements"
checker.messages.UnusedVariable.message = "W0612 local variable %r is assigned to but never used"
checker.messages.ReturnWithArgsInsideGenerator.message = "E0106 'return' with argument inside generator"
checker.messages.ReturnOutsideFunction.message = "E0104 'return' outside function"
class Linter(Abstract):
"""Pyflakes runner."""
@staticmethod
def run(path, code=None, params=None, **meta):
"""Check code with pyflakes.
"""Pyflakes support."""
from pyflakes import checker
from pylava.lint import Linter as Abstract
checker.messages.UnusedImport.message = "W0611 %r imported but unused"
checker.messages.RedefinedWhileUnused.message = "W0404 redefinition of unused %r from line %r"
checker.messages.RedefinedInListComp.message = "W0621 list comprehension redefines %r from line %r"
checker.messages.ImportShadowedByLoopVar.message = "W0621 import %r from line %r shadowed by loop variable"
checker.messages.ImportStarUsed.message = "W0401 'from %s import *' used; unable to detect undefined names"
checker.messages.ImportStarUsage.message = "W0401 '%s may be undefined, or defined from star imports: %s'"
checker.messages.UndefinedName.message = "E0602 undefined name %r"
checker.messages.DoctestSyntaxError.message = "W0511 syntax error in doctest"
checker.messages.UndefinedExport.message = "E0603 undefined name %r in __all__"
checker.messages.UndefinedLocal.message = "E0602 local variable %r (defined in enclosing scope on line %r) referenced before assignment"
checker.messages.DuplicateArgument.message = "E1122 duplicate argument %r in function definition"
checker.messages.LateFutureImport.message = "W0410 future import(s) %r after other statements"
checker.messages.UnusedVariable.message = "W0612 local variable %r is assigned to but never used"
checker.messages.ReturnWithArgsInsideGenerator.message = "E0106 'return' with argument inside generator"
checker.messages.ReturnOutsideFunction.message = "E0104 'return' outside function"
class Linter(Abstract):
linematch = '(from\s+[\w_\.]+\s+)?import\s+(?P[^#;]+)'
r = '(^|\s+|,\s*|as\s+)(?P[\w]*{0}[\w]*)'.format(
re.escape(word)
)
error_data['regex'] = r
error_data['linematch'] = linematch
errors_list.append(error_data)
elif (isinstance(error, pyflakes.messages.DuplicateArgument) and
error.__class__.__name__ not in explicit_ignore):
regex = 'def [\w_]+\(.*?(?P[\w]*{0}[\w]*)'.format(
re.escape(error.message_args[0])
)
error_data['regex'] = regex
errors_list.append(error_data)
elif isinstance(error, pyflakes.messages.LateFutureImport):
pass
elif isinstance(error, PythonError):
print(error)
else:
print('Oops, we missed an error type!', type(error))
return errors_list