Skip to content

Commit a870b66

Browse files
committed
Pylint fixes
1 parent e93df22 commit a870b66

File tree

10 files changed

+63
-62
lines changed

10 files changed

+63
-62
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@
273273
VIEW_ATTRS = {
274274
(
275275
(
276-
'{}.{}'.format(cls.__module__, cls.__name__),
277-
'.{}'.format(cls.__name__)
276+
f'{cls.__module__}.{cls.__name__}',
277+
f'.{cls.__name__}',
278278
),
279279
tuple(cls.__dict__.keys())
280280
) for cls in (

pylint_django/checkers/auth_user.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class AuthUserChecker(checkers.BaseChecker):
1010

1111
name = 'auth-user-checker'
1212

13-
msgs = {'E%d41' % BASE_ID: ("Hard-coded 'auth.User'",
14-
'hard-coded-auth-user',
15-
"Don't hard-code the auth.User model. "
16-
"Use settings.AUTH_USER_MODEL instead!"),
17-
'E%d42' % BASE_ID: ("User model imported from django.contrib.auth.models",
18-
'imported-auth-user',
19-
"Don't import django.contrib.auth.models.User model. "
20-
"Use django.contrib.auth.get_user_model() instead!")}
13+
msgs = {f'E{BASE_ID}41': ("Hard-coded 'auth.User'",
14+
'hard-coded-auth-user',
15+
"Don't hard-code the auth.User model. "
16+
"Use settings.AUTH_USER_MODEL instead!"),
17+
f'E{BASE_ID}42': ("User model imported from django.contrib.auth.models",
18+
'imported-auth-user',
19+
"Don't import django.contrib.auth.models.User model. "
20+
"Use django.contrib.auth.get_user_model() instead!")}
2121

2222
@utils.check_messages('hard-coded-auth-user')
2323
def visit_const(self, node):

pylint_django/checkers/django_installed.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ class DjangoInstalledChecker(BaseChecker):
88
name = 'django-installed-checker'
99

1010
msgs = {
11-
'F%s01' % BASE_ID: ("Django is not available on the PYTHONPATH",
12-
'django-not-available',
13-
"Django could not be imported by the pylint-django plugin, so most Django related "
14-
"improvements to pylint will fail."),
11+
f'F{BASE_ID}01': ("Django is not available on the PYTHONPATH",
12+
'django-not-available',
13+
"Django could not be imported by the pylint-django plugin, so most Django related "
14+
"improvements to pylint will fail."),
1515

16-
'W%s99' % BASE_ID: ('Placeholder message to prevent disabling of checker',
17-
'django-not-available-placeholder',
18-
'PyLint does not recognise checkers as being enabled unless they have at least'
19-
' one message which is not fatal...')
16+
f'W{BASE_ID}99': ('Placeholder message to prevent disabling of checker',
17+
'django-not-available-placeholder',
18+
'PyLint does not recognise checkers as being enabled unless they have at least'
19+
' one message which is not fatal...')
2020
}
2121

2222
@check_messages('django-not-available')

pylint_django/checkers/foreign_key_strings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ class ForeignKeyStringsChecker(BaseChecker):
4444
)
4545

4646
msgs = {
47-
"E%s10"
48-
% BASE_ID: (
47+
f"E{BASE_ID}10": (
4948
"Django was not configured. For more information run "
5049
"pylint --load-plugins=pylint_django --help-msg=django-not-configured",
5150
"django-not-configured",
5251
_LONG_MESSAGE,
5352
),
54-
"F%s10"
55-
% BASE_ID: (
53+
f"F{BASE_ID}10": (
5654
"Provided Django settings %s could not be loaded",
5755
"django-settings-module-not-found",
5856
"The provided Django settings module %s was not found on the path",

pylint_django/checkers/forms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class FormChecker(BaseChecker):
2222

2323
name = 'django-form-checker'
2424
msgs = {
25-
'W%d04' % BASE_ID: ("Use explicit fields instead of exclude in ModelForm",
26-
'modelform-uses-exclude',
27-
"Prevents accidentally allowing users to set fields, "
28-
"especially when adding new fields to a Model")
25+
f'W{BASE_ID}04': ("Use explicit fields instead of exclude in ModelForm",
26+
'modelform-uses-exclude',
27+
"Prevents accidentally allowing users to set fields, "
28+
"especially when adding new fields to a Model")
2929
}
3030

3131
@check_messages('modelform-uses-exclude')

pylint_django/checkers/json_response.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ class JsonResponseChecker(checkers.BaseChecker):
2323

2424
# configuration section name
2525
name = 'json-response-checker'
26-
msgs = {'R%s01' % BASE_ID: ("Instead of HttpResponse(json.dumps(data)) use JsonResponse(data)",
27-
'http-response-with-json-dumps',
28-
'Used when json.dumps() is used as an argument to HttpResponse().'),
29-
'R%s02' % BASE_ID: ("Instead of HttpResponse(content_type='application/json') use JsonResponse()",
30-
'http-response-with-content-type-json',
31-
'Used when HttpResponse() is returning application/json.'),
32-
'R%s03' % BASE_ID: ("Redundant content_type parameter for JsonResponse()",
33-
'redundant-content-type-for-json-response',
34-
'Used when JsonResponse() contains content_type parameter. '
35-
'This is either redundant or the content_type is not JSON '
36-
'which is probably an error.')}
26+
msgs = {f'R{BASE_ID}01': ("Instead of HttpResponse(json.dumps(data)) use JsonResponse(data)",
27+
'http-response-with-json-dumps',
28+
'Used when json.dumps() is used as an argument to HttpResponse().'),
29+
f'R{BASE_ID}02': ("Instead of HttpResponse(content_type='application/json') use JsonResponse()",
30+
'http-response-with-content-type-json',
31+
'Used when HttpResponse() is returning application/json.'),
32+
f'R{BASE_ID}03': ("Redundant content_type parameter for JsonResponse()",
33+
'redundant-content-type-for-json-response',
34+
'Used when JsonResponse() contains content_type parameter. '
35+
'This is either redundant or the content_type is not JSON '
36+
'which is probably an error.')}
3737

3838
@utils.check_messages('http-response-with-json-dumps',
3939
'http-response-with-content-type-json',

pylint_django/checkers/migrations.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class NewDbFieldWithDefaultChecker(checkers.BaseChecker):
5858

5959
# configuration section name
6060
name = 'new-db-field-with-default'
61-
msgs = {'W%s98' % BASE_ID: ("%s AddField with default value",
62-
'new-db-field-with-default',
63-
'Used when Pylint detects migrations adding new '
64-
'fields with a default value.')}
61+
msgs = {f'W{BASE_ID}98': ("%s AddField with default value",
62+
'new-db-field-with-default',
63+
'Used when Pylint detects migrations adding new '
64+
'fields with a default value.')}
6565

6666
_migration_modules = []
6767
_possible_offences = {}
@@ -117,10 +117,10 @@ class MissingBackwardsMigrationChecker(checkers.BaseChecker):
117117

118118
name = 'missing-backwards-migration-callable'
119119

120-
msgs = {'W%s97' % BASE_ID: ('Always include backwards migration callable',
121-
'missing-backwards-migration-callable',
122-
'Always include a backwards/reverse callable counterpart'
123-
' so that the migration is not irreversable.')}
120+
msgs = {f'W{BASE_ID}97': ('Always include backwards migration callable',
121+
'missing-backwards-migration-callable',
122+
'Always include a backwards/reverse callable counterpart'
123+
' so that the migration is not irreversable.')}
124124

125125
@utils.check_messages('missing-backwards-migration-callable')
126126
def visit_call(self, node):

pylint_django/checkers/models.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212

1313

1414
MESSAGES = {
15-
'E%d01' % BASE_ID: ("__unicode__ on a model must be callable (%s)",
16-
'model-unicode-not-callable',
17-
"Django models require a callable __unicode__ method"),
18-
'W%d01' % BASE_ID: ("No __unicode__ method on model (%s)",
19-
'model-missing-unicode',
20-
"Django models should implement a __unicode__ method for string representation"),
21-
'W%d02' % BASE_ID: ("Found __unicode__ method on model (%s). Python3 uses __str__.",
22-
'model-has-unicode',
23-
"Django models should not implement a __unicode__ "
24-
"method for string representation when using Python3"),
25-
'W%d03' % BASE_ID: ("Model does not explicitly define __unicode__ (%s)",
26-
'model-no-explicit-unicode',
27-
"Django models should implement a __unicode__ method for string representation. "
28-
"A parent class of this model does, but ideally all models should be explicit.")
15+
f'E{BASE_ID}01': ("__unicode__ on a model must be callable (%s)",
16+
'model-unicode-not-callable',
17+
"Django models require a callable __unicode__ method"),
18+
f'W{BASE_ID}01': ("No __unicode__ method on model (%s)",
19+
'model-missing-unicode',
20+
"Django models should implement a __unicode__ method for string representation"),
21+
f'W{BASE_ID}02': ("Found __unicode__ method on model (%s). Python3 uses __str__.",
22+
'model-has-unicode',
23+
"Django models should not implement a __unicode__ "
24+
"method for string representation when using Python3"),
25+
f'W{BASE_ID}03': ("Model does not explicitly define __unicode__ (%s)",
26+
'model-no-explicit-unicode',
27+
"Django models should implement a __unicode__ method for string representation. "
28+
"A parent class of this model does, but ideally all models should be explicit.")
2929
}
3030

3131

pylint_django/transforms/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ def fake_module_builder():
2727
http://pylint.pycqa.org/projects/astroid/en/latest/extending.html?highlight=MANAGER#module-extender-transforms
2828
"""
2929
transforms_dir = os.path.join(os.path.dirname(__file__), 'transforms')
30-
fake_module_path = os.path.join(transforms_dir, '%s.py' % re.sub(r'\.', '_', package_name))
30+
transformed_name = re.sub(r'\.', '_', package_name)
31+
fake_module_path = os.path.join(transforms_dir, f'{transformed_name}.py')
3132

32-
with open(fake_module_path) as modulefile:
33+
with open(fake_module_path, encoding='utf-8') as modulefile:
3334
fake_module = modulefile.read()
3435

3536
return astroid.builder.AstroidBuilder(astroid.MANAGER).string_build(fake_module)

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"""
55
from setuptools import setup, find_packages
66

7-
LONG_DESCRIPTION = open('README.rst').read() + "\n" + open('CHANGELOG.rst').read()
7+
with open('README.rst', encoding='utf-8') as readme, \
8+
open('CHANGELOG.rst', encoding='utf-8') as changelog:
9+
LONG_DESCRIPTION = readme.read() + "\n" + changelog.read()
810

911
setup(
1012
name='pylint-django',

0 commit comments

Comments
 (0)