Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 30 additions & 16 deletions sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand All @@ -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 = (
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
86 changes: 47 additions & 39 deletions sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
30 changes: 20 additions & 10 deletions sassutils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'
Expand Down
12 changes: 8 additions & 4 deletions sassutils/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down