Skip to content

Commit 0c39d36

Browse files
committed
Pylint fixes
1 parent 2c0daf9 commit 0c39d36

File tree

12 files changed

+71
-70
lines changed

12 files changed

+71
-70
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: 5 additions & 5 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')
@@ -46,5 +46,5 @@ def visit_classdef(self, node):
4646
continue
4747

4848
if child.targets[0].name == 'exclude':
49-
self.add_message('W%s04' % BASE_ID, node=child)
49+
self.add_message(f'W{BASE_ID}04', node=child)
5050
break

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: 18 additions & 18 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

@@ -102,12 +102,12 @@ def visit_classdef(self, node):
102102
if assigned.callable():
103103
return
104104

105-
self.add_message('E%s01' % BASE_ID, args=node.name, node=node)
105+
self.add_message(f'E{BASE_ID}01', args=node.name, node=node)
106106
return
107107

108108
if isinstance(child, FunctionDef) and child.name == '__unicode__':
109109
if PY3:
110-
self.add_message('W%s02' % BASE_ID, args=node.name, node=node)
110+
self.add_message(f'W{BASE_ID}02', args=node.name, node=node)
111111
return
112112

113113
# if we get here, then we have no __unicode__ method directly on the class itself
@@ -117,7 +117,7 @@ def visit_classdef(self, node):
117117
if method.parent != node and _is_unicode_or_str_in_python_2_compatibility(method):
118118
# this happens if a parent declares the unicode method but
119119
# this node does not
120-
self.add_message('W%s03' % BASE_ID, args=node.name, node=node)
120+
self.add_message(f'W{BASE_ID}03', args=node.name, node=node)
121121
return
122122

123123
# if the Django compatibility decorator is used then we don't emit a warning
@@ -128,4 +128,4 @@ def visit_classdef(self, node):
128128
if PY3:
129129
return
130130

131-
self.add_message('W%s01' % BASE_ID, args=node.name, node=node)
131+
self.add_message(f'W{BASE_ID}01', args=node.name, node=node)

pylint_django/tests/input/external_factory_boy_noerror.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class AuthorFactory(factory.django.DjangoModelFactory):
2222
class Meta:
2323
model = 'Author'
2424

25-
name = factory.Sequence(lambda n: 'Author %d' % n)
25+
name = factory.Sequence(lambda n: f'Author {n}')
2626

2727

2828
class BookFactory(factory.django.DjangoModelFactory):
2929
class Meta:
3030
model = 'Book'
3131

32-
title = factory.Sequence(lambda n: 'Book %d' % n)
32+
title = factory.Sequence(lambda n: f'Book {n}')
3333
author = factory.SubFactory(AuthorFactory)
3434
reviewer = factory.LazyFunction(Author.objects.first())
3535

pylint_django/tests/input/func_noerror_foreign_key_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class OtherModel(models.Model):
1616
elsething = models.OneToOneField(SomeModel, on_delete=models.CASCADE)
1717

1818
def something_doer(self):
19-
part_a = '%s - %s' % (self.something.name, self.something.timestamp)
19+
part_a = f'{self.something.name} - {self.something.timestamp}'
2020
part_b = self.elsething.name
2121
return part_a, part_b

0 commit comments

Comments
 (0)