Skip to content

Commit 3f89f8e

Browse files
atodorovcarlio
authored andcommitted
Pylint fixes
1 parent 1345b26 commit 3f89f8e

File tree

12 files changed

+34
-45
lines changed

12 files changed

+34
-45
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@
281281

282282
VIEW_ATTRS = {
283283
(
284-
("{}.{}".format(cls.__module__, cls.__name__), ".{}".format(cls.__name__)),
284+
(
285+
f"{cls.__module__}.{cls.__name__}",
286+
f".{cls.__name__}",
287+
),
285288
tuple(cls.__dict__.keys()),
286289
)
287290
for cls in (

pylint_django/checkers/auth_user.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ class AuthUserChecker(checkers.BaseChecker):
1010
name = "auth-user-checker"
1111

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

pylint_django/checkers/django_installed.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ class DjangoInstalledChecker(BaseChecker):
1010
name = "django-installed-checker"
1111

1212
msgs = {
13-
"F%s01"
14-
% BASE_ID: (
13+
f"F{BASE_ID}01": (
1514
"Django is not available on the PYTHONPATH",
1615
"django-not-available",
1716
"Django could not be imported by the pylint-django plugin, so most Django related "
1817
"improvements to pylint will fail.",
1918
),
20-
"W%s99"
21-
% BASE_ID: (
19+
f"W{BASE_ID}99": (
2220
"Placeholder message to prevent disabling of checker",
2321
"django-not-available-placeholder",
2422
"PyLint does not recognise checkers as being enabled unless they have at least"

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class FormChecker(BaseChecker):
2222

2323
name = "django-form-checker"
2424
msgs = {
25-
"W%d04"
26-
% BASE_ID: (
25+
f"W{BASE_ID}04": (
2726
"Use explicit fields instead of exclude in ModelForm",
2827
"modelform-uses-exclude",
2928
"Prevents accidentally allowing users to set fields, " "especially when adding new fields to a Model",
@@ -47,5 +46,5 @@ def visit_classdef(self, node):
4746
continue
4847

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

pylint_django/checkers/json_response.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,17 @@ class JsonResponseChecker(checkers.BaseChecker):
2424
# configuration section name
2525
name = "json-response-checker"
2626
msgs = {
27-
"R%s01"
28-
% BASE_ID: (
27+
f"R{BASE_ID}01": (
2928
"Instead of HttpResponse(json.dumps(data)) use JsonResponse(data)",
3029
"http-response-with-json-dumps",
3130
"Used when json.dumps() is used as an argument to HttpResponse().",
3231
),
33-
"R%s02"
34-
% BASE_ID: (
32+
f"R{BASE_ID}02": (
3533
"Instead of HttpResponse(content_type='application/json') use JsonResponse()",
3634
"http-response-with-content-type-json",
3735
"Used when HttpResponse() is returning application/json.",
3836
),
39-
"R%s03"
40-
% BASE_ID: (
37+
f"R{BASE_ID}03": (
4138
"Redundant content_type parameter for JsonResponse()",
4239
"redundant-content-type-for-json-response",
4340
"Used when JsonResponse() contains content_type parameter. "

pylint_django/checkers/migrations.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class NewDbFieldWithDefaultChecker(checkers.BaseChecker):
5656
# configuration section name
5757
name = "new-db-field-with-default"
5858
msgs = {
59-
"W%s98"
60-
% BASE_ID: (
59+
f"W{BASE_ID}98": (
6160
"%s AddField with default value",
6261
"new-db-field-with-default",
6362
"Used when Pylint detects migrations adding new " "fields with a default value.",
@@ -119,8 +118,7 @@ class MissingBackwardsMigrationChecker(checkers.BaseChecker):
119118
name = "missing-backwards-migration-callable"
120119

121120
msgs = {
122-
"W%s97"
123-
% BASE_ID: (
121+
f"W{BASE_ID}97": (
124122
"Always include backwards migration callable",
125123
"missing-backwards-migration-callable",
126124
"Always include a backwards/reverse callable counterpart" " so that the migration is not irreversable.",

pylint_django/checkers/models.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@
99
from pylint_django.utils import PY3, node_is_subclass
1010

1111
MESSAGES = {
12-
"E%d01"
13-
% BASE_ID: (
12+
f"E{BASE_ID}01": (
1413
"__unicode__ on a model must be callable (%s)",
1514
"model-unicode-not-callable",
1615
"Django models require a callable __unicode__ method",
1716
),
18-
"W%d01"
19-
% BASE_ID: (
17+
f"W{BASE_ID}01": (
2018
"No __unicode__ method on model (%s)",
2119
"model-missing-unicode",
2220
"Django models should implement a __unicode__ method for string representation",
2321
),
24-
"W%d02"
25-
% BASE_ID: (
22+
f"W{BASE_ID}02": (
2623
"Found __unicode__ method on model (%s). Python3 uses __str__.",
2724
"model-has-unicode",
2825
"Django models should not implement a __unicode__ " "method for string representation when using Python3",
2926
),
30-
"W%d03"
31-
% BASE_ID: (
27+
f"W{BASE_ID}03": (
3228
"Model does not explicitly define __unicode__ (%s)",
3329
"model-no-explicit-unicode",
3430
"Django models should implement a __unicode__ method for string representation. "
@@ -111,12 +107,12 @@ def visit_classdef(self, node):
111107
if assigned.callable():
112108
return
113109

114-
self.add_message("E%s01" % BASE_ID, args=node.name, node=node)
110+
self.add_message(f"E{BASE_ID}01", args=node.name, node=node)
115111
return
116112

117113
if isinstance(child, FunctionDef) and child.name == "__unicode__":
118114
if PY3:
119-
self.add_message("W%s02" % BASE_ID, args=node.name, node=node)
115+
self.add_message(f"W{BASE_ID}02", args=node.name, node=node)
120116
return
121117

122118
# if we get here, then we have no __unicode__ method directly on the class itself
@@ -126,7 +122,7 @@ def visit_classdef(self, node):
126122
if method.parent != node and _is_unicode_or_str_in_python_2_compatibility(method):
127123
# this happens if a parent declares the unicode method but
128124
# this node does not
129-
self.add_message("W%s03" % BASE_ID, args=node.name, node=node)
125+
self.add_message(f"W{BASE_ID}03", args=node.name, node=node)
130126
return
131127

132128
# if the Django compatibility decorator is used then we don't emit a warning
@@ -137,4 +133,4 @@ def visit_classdef(self, node):
137133
if PY3:
138134
return
139135

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

pylint_django/tests/input/external_factory_boy_noerror.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Test to validate that pylint_django doesn't produce
33
Instance of 'SubFactory' has no 'pk' member (no-member) warnings
44
"""
5-
# pylint: disable=attribute-defined-outside-init, missing-docstring, too-few-public-methods, consider-using-f-string
5+
# pylint: disable=attribute-defined-outside-init, missing-docstring, too-few-public-methods
66
import factory
77
from django import test
88
from django.db import models
@@ -21,14 +21,14 @@ class AuthorFactory(factory.django.DjangoModelFactory):
2121
class Meta:
2222
model = "Author"
2323

24-
name = factory.Sequence(lambda n: "Author %d" % n)
24+
name = factory.Sequence(lambda n: f"Author {n}")
2525

2626

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

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

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)