diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef4f5f73..c38ce96d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,15 +7,15 @@ repos: - id: check-yaml - id: debug-statements - repo: https://gitlab.com/pycqa/flake8 - rev: 3.7.1 + rev: 3.7.7 hooks: - id: flake8 exclude: ^docs/conf.py - repo: https://github.com/asottile/pyupgrade - rev: v1.11.1 + rev: v1.12.0 hooks: - id: pyupgrade - repo: https://github.com/asottile/add-trailing-comma - rev: v0.7.1 + rev: v1.0.0 hooks: - id: add-trailing-comma diff --git a/sass.py b/sass.py index beb297a4..24fdc350 100644 --- a/sass.py +++ b/sass.py @@ -145,8 +145,10 @@ def __init__(self, name, arguments, callable_): if not isinstance(name, string_types): raise TypeError('name must be a string, not ' + repr(name)) elif not isinstance(arguments, collections_abc.Sequence): - raise TypeError('arguments must be a sequence, not ' + - repr(arguments)) + raise TypeError( + 'arguments must be a sequence, not ' + + repr(arguments), + ) elif not callable(callable_): raise TypeError(repr(callable_) + ' is not callable') self.name = name @@ -562,13 +564,17 @@ def my_importer(path, prev): precision = kwargs.pop('precision', 5) output_style = kwargs.pop('output_style', 'nested') if not isinstance(output_style, string_types): - raise TypeError('output_style must be a string, not ' + - repr(output_style)) + raise TypeError( + 'output_style must be a string, not ' + + repr(output_style), + ) try: output_style = OUTPUT_STYLES[output_style] except KeyError: - raise CompileError('{} is unsupported output_style; choose one of {}' - ''.format(output_style, and_join(OUTPUT_STYLES))) + raise CompileError( + '{} is unsupported output_style; choose one of {}' + ''.format(output_style, and_join(OUTPUT_STYLES)), + ) source_comments = kwargs.pop('source_comments', False) if source_comments in SOURCE_COMMENTS: if source_comments == 'none': @@ -578,9 +584,11 @@ def my_importer(path, prev): ) source_comments = False elif source_comments in ('line_numbers', 'default'): - deprecation_message = ('you can simply pass True to ' - "source_comments instead of " + - repr(source_comments)) + deprecation_message = ( + 'you can simply pass True to ' + "source_comments instead of " + + repr(source_comments) + ) source_comments = True else: deprecation_message = ( @@ -596,8 +604,10 @@ def my_importer(path, prev): FutureWarning, ) if not isinstance(source_comments, bool): - raise TypeError('source_comments must be bool, not ' + - repr(source_comments)) + raise TypeError( + 'source_comments must be bool, not ' + + repr(source_comments), + ) fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() def _get_file_arg(key): @@ -670,8 +680,10 @@ def _get_file_arg(key): string = string.encode('utf-8') indented = kwargs.pop('indented', False) if not isinstance(indented, bool): - raise TypeError('indented must be bool, not ' + - repr(source_comments)) + raise TypeError( + 'indented must be bool, not ' + + repr(source_comments), + ) _check_no_remaining_kwargs(compile, kwargs) s, v = _sass.compile_string( string, output_style, source_comments, include_paths, precision, @@ -788,9 +800,11 @@ def __new__(cls, r, g, b, a): SEPARATORS = frozenset((SASS_SEPARATOR_COMMA, SASS_SEPARATOR_SPACE)) -class SassList(collections.namedtuple( - 'SassList', ('items', 'separator', 'bracketed'), -)): +class SassList( + collections.namedtuple( + 'SassList', ('items', 'separator', 'bracketed'), + ), +): def __new__(cls, items, separator, bracketed=False): items = tuple(items) diff --git a/sasstests.py b/sasstests.py index f7b3e844..e9659f93 100644 --- a/sasstests.py +++ b/sasstests.py @@ -448,47 +448,53 @@ def test_importers_raises_exception(self): def importer(path): raise ValueError('Bad path: {}'.format(path)) - with assert_raises_compile_error(RegexMatcher( - r'^Error: \n' - r' Traceback \(most recent call last\):\n' - r'.+' - r'ValueError: Bad path: hi\n' - r' on line 1 of stdin\n' - r'>> @import "hi";\n' - r' --------\^\n', - )): + with assert_raises_compile_error( + RegexMatcher( + r'^Error: \n' + r' Traceback \(most recent call last\):\n' + r'.+' + r'ValueError: Bad path: hi\n' + r' on line 1 of stdin\n' + r'>> @import "hi";\n' + r' --------\^\n', + ), + ): sass.compile(string='@import "hi";', importers=((0, importer),)) def test_importer_returns_wrong_tuple_size_zero(self): def importer(path): return ((),) - with assert_raises_compile_error(RegexMatcher( - r'^Error: \n' - r' Traceback \(most recent call last\):\n' - r'.+' - r'ValueError: Expected importer result to be a tuple of ' - r'length \(1, 2, 3\) but got 0: \(\)\n' - r' on line 1 of stdin\n' - r'>> @import "hi";\n' - r' --------\^\n', - )): + with assert_raises_compile_error( + RegexMatcher( + r'^Error: \n' + r' Traceback \(most recent call last\):\n' + r'.+' + r'ValueError: Expected importer result to be a tuple of ' + r'length \(1, 2, 3\) but got 0: \(\)\n' + r' on line 1 of stdin\n' + r'>> @import "hi";\n' + r' --------\^\n', + ), + ): sass.compile(string='@import "hi";', importers=((0, importer),)) def test_importer_returns_wrong_tuple_size_too_big(self): def importer(path): return (('a', 'b', 'c', 'd'),) - with assert_raises_compile_error(RegexMatcher( - r'^Error: \n' - r' Traceback \(most recent call last\):\n' - r'.+' - r'ValueError: Expected importer result to be a tuple of ' - r"length \(1, 2, 3\) but got 4: \('a', 'b', 'c', 'd'\)\n" - r' on line 1 of stdin\n' - r'>> @import "hi";\n' - r' --------\^\n', - )): + with assert_raises_compile_error( + RegexMatcher( + r'^Error: \n' + r' Traceback \(most recent call last\):\n' + r'.+' + r'ValueError: Expected importer result to be a tuple of ' + r"length \(1, 2, 3\) but got 4: \('a', 'b', 'c', 'd'\)\n" + r' on line 1 of stdin\n' + r'>> @import "hi";\n' + r' --------\^\n', + ), + ): sass.compile(string='@import "hi";', importers=((0, importer),)) def test_compile_string_deprecated_source_comments_line_numbers(self): @@ -1383,16 +1389,18 @@ def __eq__(self, other): class CustomFunctionsTest(unittest.TestCase): def test_raises(self): - with assert_raises_compile_error(RegexMatcher( - r'^Error: error in C function raises: \n' - r' Traceback \(most recent call last\):\n' - r'.+' - r'AssertionError: foo\n' - r' on line 1 of stdin, in function `raises`\n' - r' from line 1 of stdin\n' - r'>> a { content: raises\(\); }\n' - r' -------------\^\n$', - )): + with assert_raises_compile_error( + RegexMatcher( + r'^Error: error in C function raises: \n' + r' Traceback \(most recent call last\):\n' + r'.+' + r'AssertionError: foo\n' + r' on line 1 of stdin, in function `raises`\n' + r' from line 1 of stdin\n' + r'>> a { content: raises\(\); }\n' + r' -------------\^\n$', + ), + ): compile_with_func('a { content: raises(); }') def test_warning(self): diff --git a/sassutils/builder.py b/sassutils/builder.py index d08e8722..6f92fcb6 100644 --- a/sassutils/builder.py +++ b/sassutils/builder.py @@ -107,12 +107,16 @@ def normalize_manifests(cls, manifests): elif isinstance(manifests, collections_abc.Mapping): manifests = dict(manifests) else: - raise TypeError('manifests must be a mapping object, not ' + - repr(manifests)) + raise TypeError( + 'manifests must be a mapping object, not ' + + repr(manifests), + ) for package_name, manifest in manifests.items(): if not isinstance(package_name, string_types): - raise TypeError('manifest keys must be a string of package ' - 'name, not ' + repr(package_name)) + raise TypeError( + 'manifest keys must be a string of package ' + 'name, not ' + repr(package_name), + ) if isinstance(manifest, Manifest): continue elif isinstance(manifest, tuple): @@ -138,18 +142,24 @@ def __init__( strip_extension=None, ): if not isinstance(sass_path, string_types): - raise TypeError('sass_path must be a string, not ' + - repr(sass_path)) + raise TypeError( + 'sass_path must be a string, not ' + + repr(sass_path), + ) if css_path is None: css_path = sass_path elif not isinstance(css_path, string_types): - raise TypeError('css_path must be a string, not ' + - repr(css_path)) + raise TypeError( + 'css_path must be a string, not ' + + repr(css_path), + ) if wsgi_path is None: wsgi_path = css_path elif not isinstance(wsgi_path, string_types): - raise TypeError('wsgi_path must be a string, not ' + - repr(wsgi_path)) + raise TypeError( + 'wsgi_path must be a string, not ' + + repr(wsgi_path), + ) if strip_extension is None: warnings.warn( '`strip_extension` was not specified, defaulting to `False`.\n' diff --git a/sassutils/wsgi.py b/sassutils/wsgi.py index 9b778ba5..aed5c725 100644 --- a/sassutils/wsgi.py +++ b/sassutils/wsgi.py @@ -94,13 +94,17 @@ def __init__( error_status='200 OK', ): if not callable(app): - raise TypeError('app must be a WSGI-compliant callable object, ' - 'not ' + repr(app)) + raise TypeError( + 'app must be a WSGI-compliant callable object, ' + 'not ' + repr(app), + ) self.app = app self.manifests = Manifest.normalize_manifests(manifests) if not isinstance(package_dir, collections_abc.Mapping): - raise TypeError('package_dir must be a mapping object, not ' + - repr(package_dir)) + raise TypeError( + 'package_dir must be a mapping object, not ' + + repr(package_dir), + ) self.error_status = error_status self.package_dir = dict(package_dir) for package_name in self.manifests: