Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path=code_file,
module=None,
function='',
line=error.line,
character=0,
absolute_path=True,
)
message = Message(
source='pep257',
code=error.code,
location=location,
message=error.message.partition(':')[2].strip(),
)
messages.append(message)
except CouldNotHandleEncoding as err:
messages.append(make_tool_error_message(
code_file, 'pep257', 'D000',
message='Could not handle the encoding of this file: %s' % err.encoding
))
continue
except AllError as exc:
# pep257's Parser.parse_all method raises AllError when an
# attempt to analyze the __all__ definition has failed. This
# occurs when __all__ is too complex to be parsed.
messages.append(make_tool_error_message(
code_file, 'pep257', 'D000',
line=1, character=0,
message=exc.args[0]
))
continue
return self.filter_messages(messages)
def run(self, found_files):
messages = []
for code_file in found_files.iter_module_paths():
try:
contents = read_py_file(code_file)
tree = ast.parse(
contents,
filename=code_file,
)
except CouldNotHandleEncoding as err:
messages.append(make_tool_error_message(
code_file, 'mccabe', 'MC0000',
message='Could not handle the encoding of this file: %s' % err.encoding
))
continue
except SyntaxError as err:
messages.append(make_tool_error_message(
code_file, 'mccabe', 'MC0000',
line=err.lineno, character=err.offset,
message='Syntax Error'
))
continue
except TypeError:
messages.append(make_tool_error_message(
code_file, 'mccabe', 'MC0000',
message='Unable to parse file'
))
for code_file in found_files.iter_module_paths():
try:
contents = read_py_file(code_file)
tree = ast.parse(
contents,
filename=code_file,
)
except CouldNotHandleEncoding as err:
messages.append(make_tool_error_message(
code_file, 'mccabe', 'MC0000',
message='Could not handle the encoding of this file: %s' % err.encoding
))
continue
except SyntaxError as err:
messages.append(make_tool_error_message(
code_file, 'mccabe', 'MC0000',
line=err.lineno, character=err.offset,
message='Syntax Error'
))
continue
except TypeError:
messages.append(make_tool_error_message(
code_file, 'mccabe', 'MC0000',
message='Unable to parse file'
))
continue
visitor = PathGraphingAstVisitor()
visitor.preorder(tree, visitor)
for graph in visitor.graphs.values():
def scavenge(self, _=None):
# The argument is a list of paths, but we don't care
# about that as we use the found_files object. The
# argument is here to explicitly acknowledge that we
# are overriding the Vulture.scavenge method.
for module in self._files.iter_module_paths():
try:
module_string = read_py_file(module)
except CouldNotHandleEncoding as err:
self._internal_messages.append(make_tool_error_message(
module, 'vulture', 'V000',
message='Could not handle the encoding of this file: %s' % err.encoding
))
continue
self.file = module
self.filename = module
try:
self.scan(module_string, filename=module)
except TypeError:
self.scan(module_string)
code=error.code,
location=location,
message=error.message.partition(':')[2].strip(),
)
messages.append(message)
except CouldNotHandleEncoding as err:
messages.append(make_tool_error_message(
code_file, 'pep257', 'D000',
message='Could not handle the encoding of this file: %s' % err.encoding
))
continue
except AllError as exc:
# pep257's Parser.parse_all method raises AllError when an
# attempt to analyze the __all__ definition has failed. This
# occurs when __all__ is too complex to be parsed.
messages.append(make_tool_error_message(
code_file, 'pep257', 'D000',
line=1, character=0,
message=exc.args[0]
))
continue
return self.filter_messages(messages)