def check_syntax(filename, raise_error=False): """Return True if syntax is okay.""" with autoflake.open_with_encoding(filename, encoding=autoflake.detect_encoding(filename)) as input_file: try: compile(input_file.read(), "<string>", "exec", dont_inherit=True) return True except (SyntaxError, TypeError, UnicodeDecodeError): if raise_error: raise else: return False
def check_syntax(filename, raise_error=False): """Return True if syntax is okay.""" with autoflake.open_with_encoding( filename, encoding=autoflake.detect_encoding(filename)) as input_file: try: compile(input_file.read(), '<string>', 'exec', dont_inherit=True) return True except (SyntaxError, TypeError, UnicodeDecodeError, ValueError): if raise_error: raise else: return False
def readlines(filename): """Return contents of file as a list of lines.""" with autoflake.open_with_encoding( filename, encoding=autoflake.detect_encoding(filename)) as f: return f.readlines()
def pyflakes_count(filename): """Return pyflakes error count.""" with autoflake.open_with_encoding( filename, encoding=autoflake.detect_encoding(filename)) as f: return len(list(autoflake.check(f.read())))