Skip to content

Commit eea7247

Browse files
committed
Fix quality errors
1 parent 058c421 commit eea7247

10 files changed

Lines changed: 21 additions & 23 deletions

File tree

code_annotations/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ def _configure_coverage(self, coverage_target):
141141
if coverage_target:
142142
try:
143143
self.coverage_target = float(coverage_target)
144-
except (TypeError, ValueError):
144+
except (TypeError, ValueError) as error:
145145
raise ConfigurationException(
146146
f'Coverage target must be a number between 0 and 100 not "{coverage_target}".'
147-
)
147+
) from error
148148

149149
if self.coverage_target < 0.0 or self.coverage_target > 100.0:
150150
raise ConfigurationException(

code_annotations/contrib/sphinx/extensions/featuretoggles.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55

66
import pkg_resources
7-
87
from docutils import nodes
98
from sphinx.util.docutils import SphinxDirective
109

code_annotations/contrib/sphinx/extensions/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55

66
import pkg_resources
7-
87
from docutils import nodes
98
from docutils.parsers.rst import directives
109
from sphinx.util.docutils import SphinxDirective

code_annotations/extensions/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def __init__(self, config, echo):
7777
if self.lang_comment_definition is None: # pragma: no cover
7878
raise ValueError('Subclasses of SimpleRegexAnnotationExtension must define lang_comment_definition!')
7979

80-
# pylint: disable=not-a-mapping
8180
self.comment_regex = re.compile(
8281
self.comment_regex_fmt.format(**self.lang_comment_definition),
8382
flags=re.VERBOSE
@@ -124,13 +123,13 @@ def search(self, file_handle):
124123
try:
125124
annotation_token = inner_match.group('token')
126125
annotation_data = inner_match.group('data')
127-
except IndexError:
126+
except IndexError as error:
128127
# pragma: no cover
129128
raise ValueError('{}::{}: Could not find "data" or "token" groups. Found: {}'.format(
130129
fname,
131130
line,
132131
inner_match.groupdict()
133-
))
132+
)) from error
134133
annotation_token, annotation_data = clean_annotation(annotation_token, annotation_data)
135134
found_annotations.append({
136135
'found_by': self.extension_name,

code_annotations/find_django.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def _append_model_annotations(self, model_type, model_id, query, model_annotatio
119119
try:
120120
annotation_token = inner_match.group('token')
121121
annotation_data = inner_match.group('data')
122-
except IndexError:
122+
except IndexError as error:
123123
# pragma: no cover
124124
raise ValueError('{}: Could not find "data" or "token" groups. Found: {}'.format(
125125
self.get_model_id(model_type),
126126
inner_match.groupdict()
127-
))
127+
)) from error
128128
annotation_token, annotation_data = clean_annotation(annotation_token, annotation_data)
129129
model_annotations.append({
130130
'found_by': "django",

tests/test_django_coverage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
22
Tests for the DjangoSearch coverage functionality.
33
"""
4-
import pytest
54
from unittest.mock import DEFAULT, patch
65

6+
import pytest
7+
78
from code_annotations.find_django import DjangoSearch
89
from tests.fake_models import (
910
FakeBaseModelAbstract,

tests/test_django_generate_safelist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Tests for seeding the safelist.
44
"""
55
import os
6+
from unittest.mock import DEFAULT, MagicMock, patch
67

78
import pytest
8-
from unittest.mock import DEFAULT, MagicMock, patch
99

1010
from code_annotations.find_django import DjangoSearch
1111
from tests.helpers import DEFAULT_FAKE_SAFELIST_PATH, EXIT_CODE_FAILURE, EXIT_CODE_SUCCESS, call_script_isolated

tests/test_django_list_local_models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"""
33
Tests for listing local models.
44
"""
5-
import pytest
65
from unittest.mock import DEFAULT, MagicMock, patch
76

7+
import pytest
8+
89
from tests.helpers import call_script_isolated
910

1011

tests/test_find_django.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Tests for find annotations in Django models.
44
"""
55
import sys
6-
76
from unittest.mock import DEFAULT, patch
87

98
from code_annotations.find_django import DjangoSearch

tox.ini

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ addopts = --cov code_annotations --cov-report term-missing --cov-report xml
1616
norecursedirs = .* docs requirements
1717

1818
[testenv]
19-
deps =
19+
deps =
2020
django22: Django>=2.2,<2.3
2121
django30: Django>=3.0,<3.1
2222
django31: Django>=3.1,<3.2
2323
-r{toxinidir}/requirements/test.txt
24-
commands =
24+
commands =
2525
python -Wd -m pytest {posargs}
2626

2727
[testenv:docs]
28-
setenv =
28+
setenv =
2929
PYTHONPATH = {toxinidir}
30-
whitelist_externals =
30+
whitelist_externals =
3131
make
3232
rm
33-
deps =
33+
deps =
3434
-r{toxinidir}/requirements/doc.txt
35-
commands =
35+
commands =
3636
doc8 --ignore-path docs/_build README.rst docs
3737
rm -f docs/code_annotations.rst
3838
rm -f docs/modules.rst
@@ -41,14 +41,14 @@ commands =
4141
python setup.py check --restructuredtext --strict
4242

4343
[testenv:quality]
44-
whitelist_externals =
44+
whitelist_externals =
4545
make
46-
deps =
46+
deps =
4747
-r{toxinidir}/requirements/quality.txt
48-
commands =
48+
commands =
4949
pylint code_annotations tests test_utils setup.py
5050
pycodestyle code_annotations tests setup.py
5151
pydocstyle code_annotations tests setup.py
52-
isort --check-only --diff --recursive tests test_utils code_annotations setup.py
52+
isort --check-only --diff tests test_utils code_annotations setup.py
5353
make selfcheck
5454

0 commit comments

Comments
 (0)